DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Reproducibility as a Competitive Edge: Why Minimal Config Beats Complex Install Scripts
  • How To Validate Names Using Java
  • Protecting Java Application From Stealing Data and Source Code
  • Having Fun with the Lightning Design System for React

Trending

  • The Middleware Gap in AI Agent Frameworks
  • Evolving Spring Boot APIs to an Event-Driven Mesh
  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal
  1. DZone
  2. Data Engineering
  3. Data
  4. What You Should Know About NODE_ENV

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.

By 
Can Ho user avatar
Can Ho
·
Jul. 24, 16 · Opinion
Likes (3)
Comment
Save
Tweet
Share
114.8K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Development

  • 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

Production

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.

express.js

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

sailsjs

  • 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

mongoose

  • Disable autoIndex globally. Doing this will boost a significant performance( see http://docs.mongodb.org/manual/core/indexes/#index-creation-operations)

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.

Production (computer science) application Express Dependency Framework Template CSS Data (computing) Mongoose (web server)

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

Opinions expressed by DZone contributors are their own.

Related

  • Reproducibility as a Competitive Edge: Why Minimal Config Beats Complex Install Scripts
  • How To Validate Names Using Java
  • Protecting Java Application From Stealing Data and Source Code
  • Having Fun with the Lightning Design System for React

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook