If you ever installed an NPM package the following syntax looks very familiar to you:
npm install --save package_name
This was long the golden standard to install a package and save it as a dependency in your project.
Meaning if we didn't specify the
--save flag, it would only get locally installed and not added to the package.json file.
NPM evolved permalink
Over time NPM evolved into a huge player in package management, and ever since version 5 of NPM, we no longer need to define this
Meaning our packages will be saved by default into our package.json file.
I'm thrilled with this addition, as it's very rare to want to install a package that you don't need in your package.json file.
Installing dev dependencies using NPM permalink
We also used to have the following command to install a package as a dev dependency.
npm install --save-dev package_name
This will place the package in your dev dependencies in the package.json file.
So to recap, the normal install will install our package under the
dependencies, while the
--save-dev argument will place them under
NPM install additional flags permalink
As we saw, the default install has no flags and will install our dependency. NPM, however gives us some flags to control the options.
-P, '--save-prod`: Package will install as a dependency
--save-dev: Package will be installed as dev dependency
--save-optional: Package will be installed as an optional dependency
--no-save: Package won't be saved in package.json file
These are the most important flags we can use. However, the only one you frequently use might be the
Do keep in mind the letter flags are capital sensitive.
So to recap: we don't need to use the
--save attribute anymore. This is now the default behavior. We can provide the
-D flag to save a package as a dev dependency.
Thank you for reading this article. I hope you learned something new today. And thank you, NPM for making this available.