How to Install Node.js Dependencies for Production Environments

NodeJS ships with the awesome node package manager: NPM. NPM allows to install dependencies defined for your project via package.json.

When running a node app in production you want it to install as quick as possible. Pushing new code into the app repository will probably start the continuous integration process. In case your app passes the tests successful, your app gets deployed immediately.

Enhance the Deployment Process

NPM offers an option which allows to only install app dependencies required for production environment. Use one of the following commands to skip the devDependencies in your package.json.

npm install --production  


NODE_ENV=production npm install  

Both options will do the job for you. The first one passes the --production flag to NPM. The second sets the node environment variable NODE_ENV to production. NPM recognizes this variable and considers it before executing the npm install command.

Additionally, you can reduce the log levels to just show warnings:

npm install --loglevel warn  

Have fun with faster app installations! As always: let us know in case you're running into problems via @futurestud_io.

Explore the Library

Find interesting tutorials and solutions for your problems.