Slide 1

Slide 1 text

Work  sucks   go  surfing! http://npmjs.org/

Slide 2

Slide 2 text

@lmatteis

Slide 3

Slide 3 text

What  is  NPM? NPM is the package manager for the Node JavaScript platform

Slide 4

Slide 4 text

It puts modules in place so that node can find them... ...and manages dependency conflicts intelligently

Slide 5

Slide 5 text

Imagine you have a project that depends on a module called felix-couchdb

Slide 6

Slide 6 text

$ 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)

Slide 7

Slide 7 text

What’s going on behind the scenes $ npm install felix-couchdb ?

Slide 8

Slide 8 text

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", ...

Slide 9

Slide 9 text

Registry API http://search.npmjs.org NPM Registry You can search for packages and add your own through a RESTful HTTP JSON API

Slide 10

Slide 10 text

HTTP +   RESTful = CouchDB Registry API

Slide 11

Slide 11 text

NPM creates a ./node_modules directory and puts the felix-couchdb module in it $ ls node_modules $ cd node_modules $ ls felix-couchdb

Slide 12

Slide 12 text

Each module contains a package.json file which describes the modules dependencies... and other things

Slide 13

Slide 13 text

It reads package.json from within the felix-couchdb directory and downloads the dependencies

Slide 14

Slide 14 text

It does the same thing for each of the dependencies down the tree, until there are no more dependencies

Slide 15

Slide 15 text

You end up with a structure where everything is local to your working directory! my-project/ node_modules/ felix-couchdb/ node_modules/ request

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Keeps your dependencies structure simple

Slide 18

Slide 18 text

my-project/ node_modules/ felix-couchdb/ node_modules/ request

Slide 19

Slide 19 text

my-project/ felix-couchdb/ request depends on depends on

Slide 20

Slide 20 text

What if two modules have the same dependency?

Slide 21

Slide 21 text

./node_modules felix-couchdb /node-xml (v1) ./node_modules /node-xml (v2) My Project jsdom

Slide 22

Slide 22 text

./node_modules felix-couchdb /node-xml (v1) ./node_modules /node-xml (v2) My Project jsdom

Slide 23

Slide 23 text

./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

Slide 24

Slide 24 text

There’s a copy of the module in each project that needs it!

Slide 25

Slide 25 text

This allows programs to localize their dependencies, so that they do not clash

Slide 26

Slide 26 text

LOCALIZATION ZERO  CONFLICTS allows for

Slide 27

Slide 27 text

Great! Now you know what happens when you download an NPM module

Slide 28

Slide 28 text

What’s   next?

Slide 29

Slide 29 text

Use NPM for your own projects