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

About

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

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

backend dev integration

const apiBaseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3001' : '/'

Environment base variable

See Code Building - dotenv (.env)





Discover More
Card Puncher Data Processing
Code Building - dotenv (.env)

.env files are property files that set the environment variable for a development environment. This logic was taken from React where the defined the environment value with NODE_ENV .env: Default....
Node - Environment variable (NODE_PATH , )

in the Node process (Built-In|Well known) node environment variable Cli...
What are possible backend integrations method? API , Multi Zone,

Frontend frameworks that manage the rendering of a page need to fill them with data that comes from an external API generally a Rest API. Possibilities Support different host Support same host Description...



Share this page:
Follow us:
Task Runner