user1995781
user1995781

Reputation: 19463

Why need npm --save-dev

When installing packages in npm, why do we need to add --save-dev at the end?

Example:

npm install gulp-angular-templatecache --save-dev

From the documentation online (https://docs.npmjs.com/cli/install), it says "package will appear in your devDependencies." What is that mean? Is that mean, if I don't put --save-dev it will install on different directory?

Upvotes: 3

Views: 5438

Answers (2)

Chris Tavares
Chris Tavares

Reputation: 30411

package.json has two places to store dependency information: the "dependencies" object and the "devDependencies" object.

When you install an app and run "npm install" it pulls down both the dependencies and the devDependencies. However, if you do "npm install --production" it pulls down ONLY the dependencies, NOT the devDependencies.

The idea is that devDependencies are for things like test runners and assertion libraries; stuff you need while developing, but not stuff you need when you've actually deployed the app to production.

Upvotes: 19

Patrick Roberts
Patrick Roberts

Reputation: 51977

In the package.json file, it will automatically add the gulp-angular-templatecache module to the devDependencies object within the JSON after installing it locally in your application under node_modules like normal. The only difference is the fact that it edits the package.json file to remember that devDependency. It installs in the same location either way. So after running that, your package.json will look like this as of now:

{
  ...
  "devDependencies": {
    ...
    "gulp-angular-templatecache": "^1.5.0"
  },
  ...
}

Upvotes: 3

Related Questions