Last Updated: May 01, 2016
·
1.592K
· khaos

Node.js production environment

After deployment on production server, don't forget to run your application with environment variable NODE_ENV set to production, it's very important. That will trigger node's and libraries` internal mechanisms to use optimized code pathes, caches and other good stuff which will double or even triple application speed and produce actually lower memory footprint.

For instance, popular node.js templating engine, "Jade" (or "pug" nowadays), which is heavy, will cache all it's templates in production environment.

There is various of ways to set the production environment for node, one of the easiest:
NODE_ENV=production node server.js

This also applies if you use some process manager (and you certainly should in production) like pm2:
NODE_ENV=production pm2 start server.js