NodeJs 中 .env 的换行符后的字符串不可读

Kis*_*iya 5 javascript environment-variables node.js

我在 NodeJS 应用程序的 .env 文件中添加了一个关键变量,如下所示。

KEY="---Key---
..............
..............
"
Run Code Online (Sandbox Code Playgroud)

当我尝试从 .env 获取此变量时,它只得到“---Key---”。我不知道为什么。

小智 5

您不能将环境变量放在多行上。只需将其写在一行上,使用双引号,并\n在行间使用。您可以在这里看到它: https: //github.com/motdotla/dotenv#rules