npm install

Share this video with your friends

Social Share Links

Send Tweet
Published 10 years ago
Updated 5 years ago

npm install provides a convenient way to manage your node.js dependencies.

Man 1: [00:00] Now that we have our packaged JSON established, we can start actually installing some dependencies that we're going to use for our project.

[00:08] 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.

[00:29] 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.

[00:44] 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.

[01:06] 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.

[01:26] 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.

[01:49] 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.

[02:12] 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.

egghead
egghead
~ 35 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today