Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why NPM rocks!

Luca Matteis
November 01, 2012

Why NPM rocks!

NPM is THE Node.js Package Manager. In this presentation I describe how it works behind the scenes, and why it's so awesome.

Luca Matteis

November 01, 2012
Tweet

More Decks by Luca Matteis

Other Decks in Programming

Transcript

  1. It puts modules in place so that node can find

    them... ...and manages dependency conflicts intelligently
  2. $ mkdir my-project $ cd my-project $ npm install felix-couchdb

    Run the npm install command from within your project directory (or any of the parent folders)
  3. Fetches the package information http://search.npmjs.org/api/felix-couchdb { "_attachments": { "felix-couchdb-1.0.0.tgz": {

    "content_type": "application/octet-stream", "digest": "md5-uox/epuoVsfQnzTNMW7VqQ==", "length": 13383, "revpos": 3, "stub": true }, "felix-couchdb-1.0.1.tgz": { "content_type": "application/octet-stream", "digest": "md5-ZkipY8lB3rh7/ZSUFrtpiw==", "length": 16937, "revpos": 5, "stub": true }, "felix-couchdb-1.0.2.tgz": { "content_type": "application/octet-stream", "digest": "md5-Z3j31LH/WymAnFFygOf/Qg==", "length": 16813, "revpos": 7, "stub": true } }, "_id": "felix-couchdb", ...
  4. NPM creates a ./node_modules directory and puts the felix-couchdb module

    in it $ ls node_modules $ cd node_modules $ ls felix-couchdb
  5. It does the same thing for each of the dependencies

    down the tree, until there are no more dependencies
  6. You end up with a structure where everything is local

    to your working directory! my-project/ node_modules/ felix-couchdb/ node_modules/ request
  7. If your project is at /home/rick/my-project Node will check these

    directories for modules: IN ORDER /home/rick/my-project/node_modules /home/rick/node_modules /home/node_modules /node_modules
  8. ./node_modules felix-couchdb /node-xml (v1) ./node_modules /node-xml (v2) My Project jsdom

    They both depend on the same module, only different version of it