admin管理员组

文章数量:1296461

I added one key variable in .env file in nodeJS application as below.

KEY="---Key---
..............
..............
"

When i try to get this variable from .env it got only "---Key---". I don't know why.

I added one key variable in .env file in nodeJS application as below.

KEY="---Key---
..............
..............
"

When i try to get this variable from .env it got only "---Key---". I don't know why.

Share Improve this question asked Apr 11, 2018 at 7:01 Kishan DobariyaKishan Dobariya 731 silver badge7 bronze badges 1
  • 2 Please read the documentation: github./motdotla/dotenv#rules – str Commented Apr 11, 2018 at 7:03
Add a ment  | 

2 Answers 2

Reset to default 6

You cannot put your env variable on multiple lines. Just write it on one line, using double quotes, and use \n in between lines. You can see it here: https://github./motdotla/dotenv#rules

If you want multiple line string on env variable, you need to use \n wherever new line requires. Please see the example below.

index.js

require('dotenv').config();                                                                                                               
console.log(process.env.TEST);

.env

TEST="Hi! how are you? \n I am fine."

out put

Hi! how are you? 
I am fine.

本文标签: javascriptString not readable after newline from env in nodeJsStack Overflow