Over a million developers have joined DZone.

What You Should Know About NODE_ENV

DZone's Guide to

What You Should Know About NODE_ENV

Node.js programmers often check the NODE_ENV environment variable, but did you know the value actually set for the it can have additional implications? Read on to find out what they are.

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

NODE_ENV is an environment variable popularized by the Express framework. It specifies the environment in which an application is running such as development, staging, production, testing, etc.

By default, our application will run in development environment. And we can change the environment by changing process.env.NODE_ENV. Let’s see how frameworks and libraries will behave in different environments.


  • More logs come out
  • No views are cached
  • More verbose error messages are generated
  • Front end stuff like javascript, css, etc. aren’t minized and cached


Below are common, regardless of frameworks:

  • Middleware and other dependencies switch to use efficient code path
  • Only packages in dependencies are installed. Dependencies in devDependencies and peerDependencies are ignored.


  • View templates are cached
  • Less verbose messages are generated
  • CSS files are cached


  • CSRF is enabled
  • Response may be compressed (see https://www.npmjs.com/package/compression)
  • Models’ migration settings are forced to migrate: ‘safe’. This is a failsafe to protect against inadvertently damaging our production data during deployment
  • Error messages and stack traces from res.serverError() will still be logged, but will not be sent in the response


There’re more that I don’t list here. As you can see, setting NODE_ENV to production gives the best performance. As this variable is so important and has become globally adopted in Node.js world, you should burn this “always setting NODE_ENV to production” into your mind.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

settings ,development ,environment ,express ,performance ,node.js

Published at DZone with permission of Can Ho, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}