I have this env variable:
export MyEnvVar="new\nline"
If I run the command "echo -ne $MyEnvVar" on a Mac terminal this is what I get:
new line
When I run the following code:
require("dotenv").config();
console.log("new\nline");
console.log("");
console.log("");
console.log(process.env.MyEnvVar);
The output:
new
line
new\nline
How can I get process.env.MyEnvVar to have multiline instead of escaping it?
dotenv documentation says it support multi-line vars. https://www.npmjs.com/package/dotenv
The dotenv library supports new lines. If you use double quotes and the new line character (\n) then the new line character will create a new line.
Example in .env file:
SERVER_KEY = "abc\nefg"
will become:
abc
efg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With