I'm trying to follow a tutorial on NodeJs. I don't think I missed anything but whenever I call the process.env.NODE_ENV
the only value I get back is undefined. According to my research the default value should be 'development'. How is this value dynamically set and where is it set initially?
process.env is a reference to your environment, so you have to set the variable there.
To set an environment variable in Windows:
SET NODE_ENV=development
on OS X or Linux:
export NODE_ENV=development
You can also set it by code, for example:
process.env.NODE_ENV = 'test';
For people using *nix (Linux, OS X, etc.), there's no reason to do it via a second export command, you can chain it as part of the invoking command:
NODE_ENV=development node server.js
Easier, no? :)
In UBUNTU use:
$ export NODE_ENV=test
We ran into this problem when working with node on Windows.
Rather than requiring anyone who attempts to run the app to set these variables, we provided a fallback within the application.
var environment = process.env.NODE_ENV || 'development';
In a production environment, we would define it per the usual methods (SET/export).