I am trying to use .env file in my Node.js backend.
It has Firebase credentials as the environment variables.
privateKey=-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhk
But when I run the Node.js codes, process.env.privateKey is privateKey: '-----BEGIN PRIVATE KEY-----\\nMIIEvwIBADANBgkqh.
Finally double '\' characters are loaded.
A single '\' character should be loaded.
How can I resolve this issue?
Node isn't doing that. It's a side-effect of the REPL to avoid \n being interpreted as a newline. You could use
let private_key = process.env.privateKey.replace(/\\n/g, '\n');
console.log(private_key);
to see it without the extra slash.