--save-dev
is a command-line option used to install packages needed during the project's development phase.
When you pass --save-dev
to the npm install package-name
command, it downloads all the package files to the node_modules folder and makes an entry of that package to the devDependencies
section of the package.json file.
In the package.json file, the devDependencies
field has the list of all the packages which are required for development purposes. For example, packages such as nodemon, mocha, eslint, etc., are not needed in a production environment, so you install them using the --save-dev
option.
Note: -D
is an alias of --save-dev
, which means you can use either --save-dev
or -D
with the npm install
command.
Here is how you use --save-dev
with the npm install
command.
$npm install package-name --save-dev $npm install package-name -D
Let's see how --save-dev option installs the package with the help of an example. Suppose we want to install the nodemon
package that automatically reloads your project. This package has no use in production.
Before we install it, let's see the content of the package.json file.
Now run the npm install
command and pass nodemon
and --save-dev
option.
$npm install nodemon --save-dev
After this, open the package.json file to confirm that the nodemon package is installed as devDependencies
.