NPM --save doubt

Asked

Viewed 8,164 times

14

What difference when installing a module via NPM, use --save?

When using npm install product name, it installs the same and save the modules to the project folder.

I didn’t understand then when to use npm install product name --save

Someone to help me?

1 answer

16


The --save saves the package in the archive package.json, that serves as a reference for your project. Just when you use the command npm install all modules that have been installed with the --save shall be installed without the need to define them one by one.

Referencing npm install documentation:

-S, --save: Package will appear in dependencies.

  • What would define them one by one?

  • have to give npm install fs, npm install bower one by one on all machines where the project is downloaded. After you do the first installation, if you need to install on the server for example you only give one npm install purely

  • I’m not currently using package.json, which can be a bad thing with this?

  • If I do not miss the memory will just not write to the file, then it would be the msm thing that a npm install xxx normal

  • I just tested, this is what happens

  • 2

    Just completing, let’s say you want to send this project to me, it would be impossible to send me the node_modules folder, for that, there is package.json. You just send me the package.json and the files you programmed and I use an npm install on my machine, this npm install will read the package.json and install the dependencies.

  • So this package.json records all the modules I installed? including their version?

  • Exactly. Serves precisely to ensure that you will have the same dependencies in tds places, among other utilities

  • Cool. When I save my project to git, won’t modules come together then? Just my project?

  • Yeah, that’s the idea, you can give a ignore in the briefcase node_modules

  • got it. To close, when I clone the git project, don’t you need to install npm NOMEDOMODULO? Does it automatically get from package.json? Or have some npm update I know there....

  • has to give a single command: npm install

  • By typing npm install it searches all package dependencies and installs modules?

  • Exactly. You exchange for only 1 command avoiding errors

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.