EN
Node.js - dependencies and dev dependencies
3 points
In this article, we would like to show you the difference between dependencies and dev dependencies in Node.js.
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:
xxxxxxxxxx
1
{
2
"name": "my-app",
3
"version": "1.0.0",
4
"main": "index.js",
5
"scripts": {
6
"test": "echo \"Error: no test specified\" && exit 1"
7
},
8
"dependencies": {
9
"bcrypt": "^5.0.1",
10
"dotenv": "^10.0.0"
11
}
12
}
13
Note:
Go to the following article to see how to install npm package locally:
To install npm
package as devDependencies
, you need to add -D
flag (or --save-dev
) to the npm install
command:
xxxxxxxxxx
1
npm install -D package-name
or:
xxxxxxxxxx
1
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:
xxxxxxxxxx
1
{
2
"name": "my-app",
3
"version": "1.0.0",
4
"main": "index.js",
5
"scripts": {
6
"test": "echo \"Error: no test specified\" && exit 1"
7
},
8
"devDependencies": {
9
"nodemon": "^2.0.12"
10
}
11
}
12