DZone
Web Dev Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > 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.

Can Ho user avatar by
Can Ho
·
Jul. 24, 16 · Web Dev Zone · Opinion
Like (3)
Save
Tweet
111.11K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Basic Convolutional Neural Network Architectures
  • Maven Tutorial: Nice and Easy [Video]
  • Servlets Listeners Introduction and Examples
  • Modernize Legacy Code in Production: Rebuild Your Airplane Midflight Without Crashing

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo