Inspired by the now-outdated post 10 Cool Things You Probably Didn’t Realize npm Could Do from Isaacs, the creator of npm
, I set out to give you a few more tips on how to take advantage of this ridiculously well executed package manager.

23-12-13 Update: Now with an extra bonus tip
node
and npm
versions easilyUsing nvm
, you won’t ever have any versioning or sudo issues with npm
again. I can’t recommend this highly enough!
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
Reload your terminal, and then start by installing some other version.
nvm install 0.10.22
nvm alias default 0.10.22
Switching to another version is also really easy, and you can copy modules over when you upgrade, with nvm copy-packages <previous-version>
.
Rather than installing a package every time it gets updated, you can use the npm link
command. This command will create a symbolic link which you can later consume with npm link <pkg>
.
As an example, have the following illustrative shell session.
git clone https://github.com/bevacqua/grunt-ec2.git
cd grunt-ec2
npm link
cd ../site
npm link grunt-ec2
grunt ec2_deploy:production
If you make any changes to grunt-ec2
in your local version, they will have an immediate effect on the package installed in site
, as well. This one is also very useful if you’re a package author, as you can quickly test your package in a real usage scenario without having to publish it to npm
first.
npm init
in styleThis one is rather straightforward. You can set some values in npm
's configuration, and then using npm init
will use them when creating a package.json
file.
# add author info to npm
npm set init.author.name "$NAME"
npm set init.author.email "$EMAIL"
npm set init.author.url "$SITE"
npm init
Firstly, you can get the currently installed version of a package by executing:
npm view <pkg> version
If you set the version of a few modules in package.json
to *
, then running npm update --save
will update all those modules to the latest stable version, and since we’ve used the --save
flag, the version numbers will get persisted (overwriting the stars). This is most useful in recently started projects, but should be treated carefully in solutions which are already in production, as authors might break between updates.
npm
cacheIf you’re having any issues with an npm
package, you might have to remove it from the npm
cache before attempting to install it again.
npm clean <pkg>
npm install <pkg>
npm
modules faster!You can do that using an optimized npm publish created by dominictarr.
npm i -g npm-atomic-publish
npm-atomic-publish
npm install
, use npm i
.npm uninstall
becomes npm r
npm i --save <pkg>
devDependencies
, do npm i --save-dev <pkg>
npm
!Just do npm version <v>
! It’ll even commit and tag for you, if you’re in the context of a git
repository.
npm version 2.1.0
npm publish
If you want to access 50+ thousand packages (and rapidly growing!) in your browser, and you’re starting to get tired of the AMD module definition, you might want to give Browserify a spin. You’ll be able to use the CJS notation in the browser, and you’re even able to port modules that used the file system, thanks to some creative shimmery by substack.
And, of course, there’s a Grunt plugin for that!
--prefix <dir>
to install packages in a given directory, rather than working directorynpm
is really npm
, not NPM
, not Npm
. Just npm
. That’s it. Source:Contrary to the belief of many, “npm” is not in fact an abbreviation for “Node Package Manager”. It is a recursive bacronymic abbreviation for “npm is not an acronym”. (If it was “ninaa”, then it would be an acronym, and thus incorrectly named.)
“NPM”, however, is an acronym (more precisely, a capitonym) for the National Association of Pastoral Musicians. You can learn more about them at http://npm.org/.
In software, “NPM” is a Non-Parametric Mapping utility written by Chris Rorden. You can analyze pictures of brains with it. Learn more about the (capitalized) NPM program at http://www.cabiatl.com/mricro/npm/.
The first seed that eventually grew into this flower was a bash utility named “pm”, which was a shortened descendent of “pkgmakeinst”, a bash function that was used to install various different things on different platforms, most often using Yahoo’s yinst. If npm was ever an acronym for anything, it was node pm or maybe new pm.
So, in all seriousness, the “npm” project is named after its command-line utility, which was organically selected to be easily typed by a right-handed programmer using a US QWERTY keyboard layout, ending with the right-ring-finger in a postition to type the - key for flags and other command-line arguments. That command-line utility is always lower-case, though it starts most sentences it is a part of.
A package is:
package.json
file<name>@<version>
that is published on the registry with [3]<name>@<tag>
that points to [4]<name>
that has a “latest” tag satisfying [5]So there you have it!
What are your favorite
npm
tricks?
Using the command below, you can remove devDependencies
after npm install
. This is useful in some set ups where you deploy to a CI environment, which installs everything so that it can run your Grunt build, or something, and then deploys to the live servers.
npm prune --production
Woo, that’s ten!