npm install provides a convenient way to manage your node.js dependencies.
Now that we have our packaged JSON established, we can start actually installing some dependencies that we're going to use for our project.
The first thing we're going to install is Underscore, so I'm just going to say, "npm install -s_". And what the -s is going to do is its going to make sure that dependency that we have just installed is now listed in this package.json file.
What that means is that when somebody else downloads my project, they can simply run npm install without any arguments and using the package JSON dependencies listed, NPM will know exactly what to install.
Now that we've run this command, you can see if we open the node modules folder here, we've got Underscore installed and it's right there for us. One other way to do things--and sort of another tip--is you can use simply npm i to install. That's just a shortcut alias.
This time we're going to install Mocha. If you use -d, the dependencies are going to get installed to the dev dependencies part of your packaged JSON. So if we now look at this, we've got Underscore in our dependencies and Mocha is in our dev dependencies.
Essentially what this does is things like test libraries--like Mocha or anything else--that are only going to be used if somebody is working on your module. You want to install those into dev dependencies and so for that you can use the -D flag and it will list that dependency in the dev dependencies section.
Now, I mentioned the benefits of installing things to packaged JSONs like this. If we actually go ahead and delete our node modules folder, you can pretend you are a different developer now. We have downloaded this project and just based on this the contents of this packaged JSON, we can simply run npm i.
npm is going to look at that packaged JSON file, see that we depend both on Underscore and Mocha and then go and install both of those dependencies into our node module folder.