What is the difference between --save and --save-dev?
When you install packages with npm install
in a Node.js project, you can specify whether the package belongs in the dependencies
or devDependencies
section of your package.json
.
-
--save
(Now Default in npm v5+)- Adds the installed package to your
dependencies
. - Indicates you need this package at runtime—the application won’t function without it in production.
- Adds the installed package to your
-
--save-dev
- Adds the installed package to your
devDependencies
. - Suitable for packages needed only during development, testing, or build steps (e.g., test frameworks, linters, bundlers).
- Not required in production once your application is built or deployed.
- Adds the installed package to your
Example
# Installs a package needed at runtime. npm install express --save # Installs a package needed only for development/test processes. npm install jest --save-dev
Recommended Resource
In modern npm (v5 and later), using npm install <package>
alone automatically adds the package to dependencies
, so --save
is no longer strictly necessary. However, you still explicitly use --save-dev
for dev-only packages.
CONTRIBUTOR
TechGrind