Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at -

List of less common (however useful) NPM commands

Prepand ./bin to your $PATH

Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

export PATH="$PATH:./node_modules/.bin"

This will allow executing npm binaries installed into the .bin local and isolated current ./node_modules

Install a package and also update package.json with the installed version and package name.
npm install <module-name> --save
Install a package and also update package.json with the installed version and package name, but into the devDependencies section.
npm install <module-name> --save-dev
Set --save as a default for npm install .
npm config set save true
Generate package.json in a module directory, based on npm parmaters.
npm init
List all npm configuration flags.
npm config ls -l
Install a version not from a git repository and not from the npm directory, for example:
npm install git://
Update the global npm version.
npm update npm -g
Display the / documentation / npmjs.orf 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"}

npm test
Uninstall package (A nice thing about npm is you can always just rm -rf ./node_modules/<module_name>).
npm uninstall <module_name>
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
Test & Show the full dependency tree
npm install --dry-run
List outdated libraries compared to currently installe node_modules:
npm outdated
Lock down dependency versions:
npm shrinkwrap
Install a git specific release
npm install git://
Easter Eggs
npm xmas
npm visnup
npm substack
Copy link

isaacs commented Nov 10, 2012

This is incorrect:

npm install

But any of these will work:

npm install git+ssh://
npm install git://
npm install git+
npm install substack/node-browserify # only in the latest npm release

Copy link

Thanks, corrected.

Copy link

chevtek commented Sep 30, 2013

How do you install a package from a tag? Is it just npm install packageName --tag beta?

Copy link

@chevex Not sure if you mean npm tag or github tag.
I'm not 100% if an npm tag makes any sense, to install a github tag you should use something like this:

npm install git://[username]/[reponame]#[tag_name]
npm install git://

Copy link

@chevex meant an "npm tag" I think, re: Also like to know if you know :)

Copy link

Ah got it ( I think )

To install the package sails, using the snapshot tagged as beta:
npm install sails@beta


EDIT: turns out this works, at least as with:

Merlin:bar mike$ node -v
Merlin:bar mike$ npm -v

Copy link

Here are some of my favourites:

Update all to the latest version of all dependencies according to the version range in package.json (npm install does not check for newer versions when the version in node_modules is within the version range):

npm update

Link to the source-code for a dependency to test changes locally before publishing new versions:

# symlink ~/devel/module-a/node_modules/module-b -> /usr/local/lib/node_modules/module-b -> ~/devel/module-b
~/devel/module-a $ npm link ../module-b

To set default values for npm init:

npm config set init-author-name "Your name"
npm config set init-author-email ""
npm config set init-license MIT

To set project-specific config. I.e. publish to a private repo. Create a .npmrc file in the project folder:


By default npm uses .gitignore to ignore files to include in the published package. If you need a different set of ignores, use .npmignore as well.

Not part of the npm cli, but I find npm-check a lot easier than npm outdated. Instead of only listing the outdated depenencies, it can print out commands to copy-paste to update each outdated dependency, or use the interactive mode where you just mark the dependencies to update.
interactive npm-check

Copy link

You could run > npm outdated -g

Copy link

> npm substack
Replace your configs with services

on windows*

Copy link

Copy link

ghost commented Jul 29, 2017

######Install a version not from a git repository and not from the npm directory, for example:

there are 2 "not"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment