I\'m attempting to load an RSA private key into my nodejs application using environment variables, but the newlines seem to be being auto-escaped.
For the following, ass
If you're using dotenv: We solved it this way, with newlines and JSON.parse (this allows any backslash escaped chars within the string, not just \n
):
in .env:
MY_KEY='-----BEGIN CERTIFICATE-----\nabcde...'
in server.ts:
myKey = JSON.parse(`"${process.env.MY_KEY}"`), // convert special chars
See thread: https://github.com/motdotla/dotenv/issues/218