skip to Main Content

The app runs on a shared server at namecheap. When I hardcode the env variable as a regular variable inside server.js like let MONGO_URL=blablabla the app works OK.

When i use process.env.MONGO_URL instead, it crashes. Any ideas why it is happening?

note: I have my env variable installed on node console of cpanel.

note2: The problem is not MONGO_URL, using process.env.PORT crashes the app too.

2

Answers


  1. Chosen as BEST ANSWER

    Solved.

    Added to the server.js

    if (process.env.NODE_ENV != 'production') {
        require('dotenv').config(); 
      }
    

    And switched the app mode to "production". Now process.env works.


  2. is there process.env.MONGO_URL in list of variable that you installed on node console of cpanel?

    if it is not, put it on that list and try again

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search