How to set NODE_ENV to production/development in OS X


Question

For use in express.js environments. Any suggestions?

1
291
3/15/2018 5:25:46 PM

Accepted Answer

Before running your app, you can do this in console,

export NODE_ENV=production

Or if you are in windows you could try this:

SET NODE_ENV=production

or you can run your app like this:

NODE_ENV=production node app.js

You can also set it in your js file:

process.env.NODE_ENV = 'production';

But I don't suggest to do it in your runtime file, since it's not easy to open up VIM in your server and change it to production. You can make a config.json file in your directory and everytime your app runs, it reads from it and sets the configuration.

616
1/27/2015 10:04:45 AM

in package.json:

{
  ...
  "scripts": {
    "start": "NODE_ENV=production node ./app"
  }
  ...
}

then run in terminal:

npm start

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon