Useful npm commands

A collection of useful npm commands for my own reference.

As as a frequent user of Node and npm I’m often looking for short cuts and quick commands I can use to speed up my work flow. I’ve combined a few of my favourites here for my own reference.

I will keep this post updated as I find more useful commands.

List global packages with or without dependencies

# List all global packages
$ npm ls --global
$ npm ls -g

# List packages without their dependencies
$ npm ls --global --depth=0
$ npm ls -g --depth=0

Perfect for seeing what packages you’ve installed and (perhaps) need to remove.

Install and add to dev dependencies

# Install bower and save in package.json
$ npm install --dev <module-name>
$ npm i -D <module-name>

A quick command to install and save in your package.json file’s devDependencies.

Show all versions of a package on npm

# List all versions of a package on npm
$ npm show <module-name> versions

A quick way to find the right version on npm.

Go to information about a npm package

# Opens your browser to the package repo
$ npm repo <module-name>

# Opens your browser to the bug tracker for the package
$ npm bugs <module-name>

# Opens your browser to the package home page
$ npm home <module-name>

# Opens your browser to the package readme.md
$ npm docs <module-name>

Each npm package has an associated files you can open. I love using this to find open issues, bug reports or just get more info about a package.

Set save as the default for npm install

$ npm config set save true

Useful for auto-adding packages to you package.json file.