About
NODE_ENV is a environment variable that contains the type of environment the code run on.
Articles Related
Value
- NODE_ENV=development
- NODE_ENV=production
- NODE_ENV=test
Example within the script of package.json with jest and the cross-env cli
"scripts": {
"test": "cross-env NODE_ENV=test yarn jest ./src",
},
"devDependencies": {
"cross-env": "^5.2.0",
"jest": "^21.2.1",
}
Usage
Minification
if (process.env.NODE_ENV !== 'production') {
analytics.disable();
}
When you compile the app with npm run build, the minification step will strip out this condition, and the resulting bundle will be smaller.
Api
const apiBaseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3001' : '/'