Node - Node Env (Prod,Dev,Test,..)

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > Node.js

1 - About

NODE_ENV is a environment variable that contains the type of environment the code run on.

Advertising

3 - Value

  • NODE_ENV=development
  • NODE_ENV=production
  • NODE_ENV=test

Example within the script of package.json with jest and the cross-env cli

package.json
"scripts": {
    "test": "cross-env NODE_ENV=test yarn jest ./src",
},
"devDependencies": {
        "cross-env": "^5.2.0",
        "jest": "^21.2.1",
}

4 - Usage

4.1 - 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.

4.2 - Api

backend dev integration

const apiBaseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3001' : '/'
web/javascript/node/node_env.txt · Last modified: 2019/06/18 10:16 by gerardnico