2 Methods to Skip Installing Development Packages in npm

2 Methods to Skip Installing Development Packages in npm

The npm separates runtime and development packages within the package.json file using the dependencies and devDependencies sections. Runtime dependencies are required when the application is running, while development dependencies are typically used for testing, building, and other development tasks. For production deployments, installing only the packages needed at runtime is often preferred. This tutorial provides 2 methods how to skip installing development packages in npm.

Example package.json:

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "Project description",
  "license": "MIT",
  "dependencies": {
      "express": "^5.2.0"
  },
  "devDependencies": {
      "vite": "^8.1.0"
  }
}

Method 1 - omit=dev option

The npm provides the --omit=dev option, which prevents packages listed in the devDependencies section from being installed. The option can be used with the install command as shown below:

npm install --omit=dev

Method 2 (Linux) - NODE_ENV before command

Another way to install only production dependencies is to set the NODE_ENV environment variable to production for the installation command. With this variable in place, npm skips development packages during the install process.

NODE_ENV=production npm install

Leave a Comment

Cancel reply

Your email address will not be published.