Languages
[Edit]
EN

Node.js - dependencies and dev dependencies

3 points
Created by:
Geospatial-Palus
630

In this article, we would like to show you the difference between dependencies and dev dependencies in Node.js.

Dependencies

When you install an npm package locally you install it as a normal dependency.

It is automatically added to the package.json file to the depencencies list.

Example package.json with dependencies:

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "bcrypt": "^5.0.1",
    "dotenv": "^10.0.0"
  }
}

Note:

Go to the following article to see how to install npm package locally:

Dev dependencies

To install npm package as devDependencies, you need to add -D flag (or --save-dev) to the npm install command:

npm install -D package-name

or:

npm install --save-dev package-name

The development dependencies are required only during the development process (e.g unit testing).

They are added to the package.json file to the devDependency list.

Example package.json with devDependencies list:

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "nodemon": "^2.0.12"
  }
}

Alternative titles

  1. Node.js - normal dependencies and dev dependencies
  2. Node.js - dependencies vs dev dependencies
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join