What is the difference between:
npm install [package_name] --save
and
npm install [package_name] --save-dev
What does this mean?
What is the difference between:
npm install [package_name] --save
and
npm install [package_name] --save-dev
What does this mean?
By default, NPM simply installs a package under node_modules. When you're trying to install dependencies for your app/module, you would need to first install them, and then add them to the
dependencies
section of yourpackage.json
.--save-dev
adds the third-party package to the package's development dependencies. It won't be installed when someone installs your package. It's typically only installed if someone clones your source repository and runsnpm install
in it.--save
adds the third-party package to the package's dependencies. It will be installed together with the package whenever someone runsnpm install package
.Dev dependencies are those dependencies that are only needed for developing the package. That can include test runners, compilers, packagers, etc. Both types of dependencies are stored in the package's
package.json
file.--save
adds todependencies
,--save-dev
adds todevDependencies
npm install documentation can be referred here.
--save-dev
saves semver spec into "devDependencies" array in your package descriptor file,--save
saves it into "dependencies" instead.--save-dev is used for modules used in development of the application,not require while running it in production envionment --save is used to add it in package.json and it is required for running of the application.
Example: express,body-parser,lodash,helmet,mysql all these are used while running the application use --save to put in dependencies while mocha,istanbul,chai,sonarqube-scanner all are used during development ,so put those in dev-dependencies .
npm link or npm install will also install the dev-dependency modules along with dependency modules in your project folder
A perfect example of this is:
In this case, you'd want to have Typescript (a javascript-parseable coding language) available for development, but once the app is deployed, it is no longer necessary, as all of the code has been transpiled to javascript. As such, it would make no sense to include it in the published app. Indeed, it would only take up space and increase download times.
The difference between
--save
and--save-dev
may not be immediately noticable if you have tried them both on your own projects. So here are a few examples...Lets say you were bulding an app that that used the moment package to parse and display dates. Your app is a scheduler so it really needs this package to run, as in: cannot run without it. In this case you would use
This would create a new value in your package.json
When you are developing, it really helps to use tools such as test suites and may need jasmine-core and karma. In this case you would use
This would also create a new value in your package.json
You do not need the test suite to run the app in its normal state, so it is a
--save-dev
type dependency, nothing more. You can see how if you do not understand what is really happening, it is a bit hard to imagine.Taken directly from NPM docs docs#dependencies
Even in the docs, it asks you to use --save-dev for modules such as test harnesses.
I hope this helps and is clear.
Clear answers are already provided. But it's worth mentioning how
devDependencies
affects installing packages:See: https://docs.npmjs.com/cli/install