process.env在Node应用程序中未定义

时间:2022-01-10 23:08:30

When running my Node app with node server.js, process.env returns undefined, so I'm unable to access any environment variables. This also seems to occur when I attempt to deploy my app to Duostack.

当使用节点server.js运行我的Node应用程序时,process.env返回undefined,因此我无法访问任何环境变量。当我尝试将我的应用程序部署到Duostack时,似乎也会发生这种情况。

Calling process.env from the command line seems to work, though:

但是,从命令行调用process.env似乎有效:

$ node
> process.env
{ MANPATH: '/opt/local/share/man:',
  TERM_PROGRAM: 'Apple_Terminal',
...

Any idea what could be going wrong?

什么可能出错?

1 个解决方案

#1


39  

I figured it out. process is an object (https://nodejs.org/api/process.html), but I'd defined my own function (also called process) that overwrote it. Changing the name of my function fixed the problem.

我想到了。 process是一个对象(https://nodejs.org/api/process.html),但是我定义了我自己的函数(也称为process)来覆盖它。更改我的功能名称修复了问题。

#1


39  

I figured it out. process is an object (https://nodejs.org/api/process.html), but I'd defined my own function (also called process) that overwrote it. Changing the name of my function fixed the problem.

我想到了。 process是一个对象(https://nodejs.org/api/process.html),但是我定义了我自己的函数(也称为process)来覆盖它。更改我的功能名称修复了问题。