20

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?

1 Answer 1

59

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.

3
  • I had this problem too, don't create a method name process
    – onmyway133
    Aug 29, 2017 at 13:40
  • 1
    I can't believe I copy-pasta'd a process() function for testing only to find out it's a reserved object. So much for dangerous tutorials.
    – Nogurenn
    Sep 14, 2017 at 9:33
  • Funny how many people did that silly same mistake ! Aug 25, 2021 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.