Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install vs. edit package.json and npm update

Tags:

node.js

npm

Curious what is the difference between the two procedures:

  1. npm install xyz
  2. edit package.json, adding required module names like this:

"dependencies": {
    "express": "~3.4.4",
    "mongodb": "*",
    "body-parser": "*",
    "bson": "*"
  },

and then npm update

like image 614
János Avatar asked Mar 15 '23 23:03

János


2 Answers

Basically package.json stores the dependencies of you application. Everything under "dependencies" is updated when you do npm update .

"bson": "*" means that it will update to latest version of module bson.

When you do npm install xyz you are basically installing xyz without telling package.json. Next time you do npm update npm will update everything under dependencies but not xyz

Here are the commands that will help you :

  1. npm install xyz This will install xyz without telling package.json.
  2. npm install --save xyz This will install xyz and also update package.json, so that when next time you do npm update it will update xyz as well.
  3. npm install This will install everything under dependencies in package.json.
  4. npm update This will update everything under dependencies in package.json.
like image 107
MegaMind Avatar answered Mar 18 '23 11:03

MegaMind


If you just do npm install package, it doesn't add it to your package.json. Then, if you want to npm update or publish your package, it won't have all of the required packages.

You can also do npm install --save package, which will install and add to your package.json. (see the docs)

like image 26
Scimonster Avatar answered Mar 18 '23 13:03

Scimonster