1

I'm new to nodejs and npm, just a question on dependencies and devDependencies

When I create a new react or Angular project, then I added a new required package by

npm install xxx --save

so the command above add the new package entry to "dependencies" in package.json file.

then I run npm start. The project is working OK and it is using the package I just installed.

But when I run npm start, I'm still in development environment, isn't it? and if the entry is not added to devDependencies, how can the application still run in development? I'm confused

1 Answers1

5

The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. So while development we use both of them. For more details check here.

Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27
  • so can I say the dependencies that production required is also the packages in `"dependencies"` , so production = dependencies –  Nov 29 '19 at 03:35
  • 2
    Yes. For example we use nodemon, so that after any change we dont have to restart the server. It is very helpful in development. We put nodemon in devDependencies not dependencies. – Mritunjay Upadhyay Nov 29 '19 at 04:46
  • so what's the difference between `npm install xxx --save` and `npm install xxx --production`? they all add entries to `"dependencies"`? –  Nov 29 '19 at 04:53
  • 1
    When you run npm install it will install both devDependencies and dependencies. To avoid install devDependencies run npm install xxx --production – Mritunjay Upadhyay Nov 29 '19 at 04:57
  • sorry I'm still confused. do you mean `npm install xxx --save` and `npm install xxx --production` both will only add entries to "dependencies"? if so, then what's the difference between them? –  Nov 29 '19 at 05:11
  • `npm install xxx --save` do add entries to both `dependencies` and `devDependencies`. If you write `npm install xxx --production`, it will specifically add entry in dependencies only. If you write `npm install xxx --dev`, it will specifically add entry in devDependencies only. – Mritunjay Upadhyay Nov 29 '19 at 05:29
  • sorry, still confused. I think you mention that `npm install xxx` add entry in both of dependencies and devDependencies. If that's the case, what's the difference between `npm install xxx` and `npm install xxx --save`? –  Nov 29 '19 at 05:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203295/discussion-between-mritunjay-upadhyay-and-secondimage). – Mritunjay Upadhyay Nov 29 '19 at 05:41