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
Node will take the environment vars and escape them to avoid interpolation:
% export X="hey\nman"
% echo $X
hey
man
% node
> process.env['X']
'hey\\nman'
>
One option is to set the variable outside of node with actual newlines:
% export X="hey
dquote> man"
% node
> process.env['X']
'hey\nman'
> console.log(process.env['X'])
hey
man
undefined
>
This also works within script files, just use newlines within quotes. You can also do a replacement:
% export X="hey\nman\ndude\nwhat"
% node
> console.log(process.env['X'].replace(/\\n/g, '\n'))
hey
man
dude
what