Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    npm install

    Ben ClinkinbeardBen Clinkinbeard

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

    javascriptJavaScript
    nodeNode.js
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss