本文介绍了在Node app中未定义process.env的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

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.

从命令行调用process.env似乎可以,但是:

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

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

有什么想法会出问题吗?

Any idea what could be going wrong?

推荐答案

我知道了. process是一个对象( https://nodejs.org/api/process.html ) ,但是我定义了自己的函数(也称为process)来覆盖它.更改我的函数的名称可以解决此问题.

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.

这篇关于在Node app中未定义process.env的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:00