20

In a node project I found 2 kind of dependencies:

    "dependencies": {
        "axios": "0.9.1",
        "express": "4.13.4",
        "lodash": "4.6.1",
        "react": "^0.14.7",
        "react-dom": "^0.14.7",
        "react-redux": "^4.4.0",
        "react-router": "^2.0.0",
        "redux": "^3.3.1"
      },
      "devDependencies": {
        "babel-core": "^6.5.2"
}

I know the author install it via npm install babel-core --save -dev

but what is that for? when you push your code, the devDependencies module is still there.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Maria Jane
  • 2,353
  • 6
  • 23
  • 39
  • 16
    Possible duplicate of [What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?](http://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies) – dting Sep 27 '16 at 05:15
  • 2
    when you search on google , the first result will answer your question. – Deendayal Garg Sep 27 '16 at 05:19
  • Best Link to be referred for the difference is - https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies] – Renuka Misal Feb 05 '18 at 15:03
  • This is the best link to be refered : https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies – Renuka Misal Feb 05 '18 at 15:06

3 Answers3

16

I wrote an article about this however it was taken down.

Snippets from the article:

mod-a
  dev-dependents:
    - mod-b
  dependents:
    - mod-c

mod-d
  dev-dependents:
    - mod-e
  dependents:
    - mod-a

----

npm install mod-d

installed modules:
  - mod-d
  - mod-a
  - mod-c

----

checkout the mod-d code repository

npm install

installed modules:
  - mod-a
  - mod-c
  - mod-e

Publishing to npm

If you are publishing to npm, then it is important that you use the correct flag for the correct modules. If it is something that your npm module needs to function, then use the "--save" flag to save the module as a dependency. If it is something that your module doesn't need to function but it is needed for testing, then use the "--save-dev" flag.

# For dependent modules
npm install dependent-module --save

# For dev-dependent modules
npm install development-module --save-dev

Not for npm

If you aren't publishing to npm, it technically doesn't matter which flag you use. However, I find it a good practice to use the "--save" flag for modules that introduce non-standard code into the source files. Then use the "--sav-dev" flag for modules that are required for your compiler to function.

# For modules that introduce non-standard source code
npm install source-module --save

# For modules that your compiler needs to function
npm install compiler-module --save-dev
Daniel Tonon
  • 9,261
  • 5
  • 61
  • 64
  • 3
    Yes I wrote the aritcle :P – Daniel Tonon May 09 '17 at 09:45
  • Yes both of the explanation helps me alot. – Faris Rayhan Oct 01 '17 at 04:50
  • Ok I figured out why the link stopped working. I only have a free account on LinkedIn and apparently free accounts seem to have an article view limit. I'm currently finding a new home for it. I will update the answer when it is available to be read at its new home. – Daniel Tonon Oct 28 '17 at 15:18
  • An update on what's happening with the article. I tried getting it published, I had interest from publishers but needed to add more details to it about more things if they were going to publish it. I haven't finished updating the article yet with the changes they requested (I've been procrastinating a bit). I also need to update it since the npm website has changed styling recently. – Daniel Tonon May 04 '18 at 10:24
  • FYI, I never republished the article. The answer here gets across what I want to say sufficiently enough I think. – Daniel Tonon Feb 06 '22 at 00:58
13

Dependencies vs dev dependencies

Dev dependencies are modules which are only required during development whereas dependencies are required at runtime. If you are deploying your application, dependencies has to be installed, or else your app simply will not work. Libraries that you call from your code that enables the program to run can be considered as adependencies.

Eg- React , React - dom

Dev dependency modules need not be installed in the production server since you are not gonna develop in that machine .compilers that covert your code to javascript , test frameworks and document generators can be considered as dev-dependencies since they are only required during development .

Eg- ESLint , Babel , webpack

5

Main difference between the two is:

-in devdependencies, developer customize or modify the node package according to the requirement. For example while making grunt task we change the task as per requirement in Gruntfile, same as case with babel you are using.

-in dependencies, developer directly use the node package without the change ex-express.

Hopefully it clears your doubt.

Nitin Nema
  • 137
  • 2
  • 4