How can i define enviroment at NodeJS, Express4?
Don't work. Output error in console.
NODE_ENV=production node app.js
EDIT:
http://rghost.net/57634264/image.png
"NODE_ENV" is unknown command.
From the express 4 documentation:
settings
The following settings will alter how Express behaves:
- env Environment mode, defaults to process.env.NODE_ENV (NODE_ENV environment variable) or "development"
Start your app with the command you posted:
NODE_ENV=production node app.js
If you've used express correctly (can't tell here as you've not posted code), you can access NODE_ENV
through the app.get()
method, which, in this context, will get the setting variable.
if (app.get('env') == 'production') {
// do something only production does
}
This is because windows CMD is a lot different than POSIX-like shells (used in linux and osx), which is what most of the tutorials and documentation for node userland is written for.
I recommend either using the Git Bash terminal that comes with git(link) to get a POSIX-like shell, or use the windows command to set the variable (takes two commands):
set NODE_ENV=production
node app.js