npm

Getting Started

List everything you have installed in the current directory

npm ls

Search the registry for packages matching terms

npm search [search terms]

Install a package

npm install [<name> [<name> ...]] [--save|--save-dev|--save-optional]

This command installs a package, or packages, and any packages that it depends on in the current directory. If the package has a shrinkwrap file, the installation of dependencies will be driven by that.

If no package.json exists, these options are ignored. If it exists, they'll update them if they are already there.

  • --save: Package will appear in your depedencies.
  • --save-dev: Package will appear in your devDependencies.
  • --save-optional: Package will appear in your optionalDependencies.
  • --global: Package will be installed globally (if you want to use it as a command line tool for example)

Install a package in the version

npm install <module-name>@<version-name>

Uninstall a package, completely removing everything npm installed on its behalf

npm uninstall

Update all the packages listed to the latest version (specified by the tag config). Also install missing packages

npm update [<name> [<name> ...]]

Update the global npm version

npm update npm -g

Display the README.md / documentation / npmjs.org page of a give library

npm docs <module-name>

Run package test suite, based on setup in package.json in

"scripts" : {"test" : "node testfile.js"}

List outdated libraries compared to currently installed node_modules

npm outdated

Lock down dependency versions

npm shrinkwrap

Develop

Interactively create a package.json file

npm init

Asks you a bunch of questions, and then writes a package.json for you. If you already have a package.json file, it'll read that first, and default to the options in there.

Install a git specific release

npm install git://github.com/Marak/colors.js#v0.6.0

Locally edit a dependency

npm edit <module_name>

Setup editor for npm edit

npm config set editor "sublime"

Publish a package not under the default "latest" tag

npm publish --tag beta