Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.env undefined in Node app

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.

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?

like image 485
nickpatrick Avatar asked Mar 28 '11 10:03

nickpatrick


People also ask

Why is process env port undefined?

When trying to access process. env. PORT it'll return undefined if you've not setup that environment variable in the shell that you're trying to run your system. You can set the environment variable up before you run node app.

What is process env in Node?

In Node. js, process. env is a global variable that is injected during runtime. It is a view of the state of the system environment variables. When we set an environment variable, it is loaded into process.

What is process env file?

The process.env property is an inbuilt application programming interface of the process module which is used to get the user environment. Syntax: process.env. Return Value: This property returns an object containing the user environment.


1 Answers

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.

like image 82
nickpatrick Avatar answered Oct 09 '22 06:10

nickpatrick