13

I'm learning basic node.js and realized that I can use a package installed globally on my pc without installing it in my project.

Currently my dependencies look like this:

"dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "http-errors": "~1.6.3",
    "morgan": "~1.9.1",
    "pug": "2.0.0-beta11"
  },
  "devDependencies": {
    "jasmine": "^3.6.1"
  }

I was using nodemon but just realized that it's not listed as a dev dependency, should I add it with npm i --save-dev nodemon as a good practice?

I guess it must be declared as dependency in case this was a collaborative project but I'm not sure.

2
  • 2
    I don't think it's necessary. If you're collaborating with other people, it's up to them how they run the project. Aug 14, 2020 at 8:28
  • Oh you're right. What if it is a project's dependency such as express though? Can I use express in my project if it is installed globally without adding it in my dependencies?
    – Chefcito
    Aug 14, 2020 at 18:04

2 Answers 2

9

If you install nodemon as a Dev dependency, then it will not be locally installed, it'll not be available in your system path. But if you install nodemon globally then it'll be installed on your system path globally.

To install nodemon globally:

npm install -g nodemon

To install nodemon as a dev dependecy:

npm install --save-dev nodemon

Thanks!

8

I think you should add it to dependencies just in case you use it to run your application by some package.json defined script:

"scripts": {
"develop": "nodemon src/server"

So it works for any develop who runs: npm run develop

3
  • What if it is a project's dependency such as express though? Can I use express in my project if it is installed globally without adding it in my dependencies? If so, It'd be a problem in a collaborative project I guess?
    – Chefcito
    Aug 14, 2020 at 18:08
  • you should add it to package.json cause it is a dependence which will be always used by your app. I mean, any user will need to install express globally or locally, but it is necessary to run the code.
    – Lamelas84
    Aug 17, 2020 at 9:17
  • Got it. Thank you. :D
    – Chefcito
    Aug 17, 2020 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.