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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With