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.
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"
}
}