4 ms·
There are a number of ways to do this but when I first started with node I started by using some different files which hold environment variables. You can then
by funthree 15y ago
There are a number of ways to do this but when I first started with node I started by using some different files which hold environment variables. You can then export some environment variables based on where you are running your code (production, dev, staging, etc)
For instance you might have a .production file
export NODE_ENV="production"
export NODE_PORT="80"
And a .development file
export NODE_ENV="development"
export NODE_PORT="3000"
Before you run "node app" just link to your variables with "$ . .production" or "$ sh .production"
Again there are many ways to accomplish this same thing but this way is pretty straightforward if you are familiar with linux.
EDIT: To add to the link to configuration pkrumins posted (http://expressjs.com/guide.html#configuration http://expressjs.com/guide.html#configuration)
process.env will hold all of your environment variables, and express.js will read "NODE_ENV" internally. A combination of the above, and setting up corresponding internal configuration in your node.js app will provide for a very clean setup.