nstalling stuff: npm install
You probably got npm because you want to install stuff. That's what package managers do, they install stuff.
npm install blerg installs the latest version of blerg . You can also give install a tarball, a folder, or a url to a tarball. If you run npm install without any arguments, it tries to install the current folder.
This command can do a lot of stuff. npm help install will tell you more than you ever wanted to know about it.
Showing things: npm ls
The npm ls command shows what's on your system, and also what's available in the registry. The arguments are beautifully colored greps. For instance npm ls installed would show you what's installed on your system. npm ls installed marak would show you all the packages installed on your system created by Marak.
npm help ls for more info.
Updating packages: npm update
The update command does a few things.
- Search the registry for new versions of all the packages installed.
- If there's a newer version, then install it.
- Point dependent packages at the new version, if it satisfies their dependency.
- Remove the old versions, if no other package names them as a dependency.
So basically, update behaves a lot like a "standard" package manager's update command, except that it also checks to make sure that the new version isn't going to break anything before it points stuff at it.
You see, npm keeps you out of dependency hell.
Development: npm link
The link command symlinks a package folder into your system, so that changes are automatically reflected. It also installs the "dependencies" and "devDependencies" packages from your package.json file.
This is one of the most useful tools for developing programs with node. Give your thing a name and a version in a package.json file. Specify a few dependencies and a main module. Then run npm link , and go to town coding it and testing it out in the node repl. It's great.
Making a Package: The package.json file.
The package.json file goes in the root of your package. It tells npm how your package is structured, and what to do to install it.
Most of the time, you only need the "name" , "version" , and "main" fields (even for node-waf compiled addons).
If you don't know json, then it's about time you learn it. It's pretty easy.
|