process.env undefined in Node app

16,868

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.

Share:
16,868

Related videos on Youtube

nickpatrick
Author by

nickpatrick

Updated on October 30, 2020

Comments

  • nickpatrick
    nickpatrick over 3 years

    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?

  • onmyway133
    onmyway133 over 6 years
    I had this problem too, don't create a method name process
  • Nogurenn
    Nogurenn over 6 years
    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.
  • Steve Lng C
    Steve Lng C over 2 years
    Funny how many people did that silly same mistake !

Related