Logo

What is the --save option for npm install?

In older versions of npm (prior to npm v5), adding --save when installing a package ensured that the package would be listed under dependencies in your project’s package.json. For instance:

npm install lodash --save

would add an entry like:

{ "dependencies": { "lodash": "^4.17.21" } }

Behavior After npm v5

Starting with npm v5, npm install <package> automatically saves the installed package to the dependencies section of package.json by default. As a result, using --save is no longer necessary—npm does this for you automatically. Therefore:

npm install lodash

already updates package.json with the dependency. The --save flag is effectively a no-op in newer versions of npm, though you can still use it without causing any issues.

Recommended Resource

Summary

  • Pre-npm v5: --save was essential to add a package to dependencies.
  • npm v5+: Saving to dependencies happens by default when you run npm install <package>.
  • Other Flags:
    • --save-dev: Installs and saves a package under devDependencies.
    • --save-exact: Installs and pins the exact version (no caret ^ in package.json).
CONTRIBUTOR
TechGrind