npm is a package manager for the Node.js software platform. A package management system helps to streamline the installation, updating, and configuration of software packages. This way, one can easily manage the dependencies of a project, without any worries, in a scriptable manner.
The following is a look into the official website for npm:
As Grunt is a JavaScript project built using Node, it naturally uses npm for version control. npm will also be used to install and update Grunt plugins and Bower. The npm registry also hosts a variety of other tools, including the Mocha testing engine, the Jade templating engine, and the ExpressJS web framework.
Traditionally, if someone wanted to install a package that was built using Node.js, one would need to download the necessary files and build the package manually. Using npm, one can install and update software packages with a simple command. It also allows the installation of projects of a specific version, a technique that will be used throughout this book to ensure that project instructions align consistently with the software.
Since npm comes with Node, it suffices to install the Node platform to set up npm.
The following steps will cover the installation of npm on Windows through the Node installer:
Download the
.msi
installer located at http://nodejs.org/download/.
The following steps will cover the installation of npm via the command line on Mac OS X and Linux:
Download the
.pkg
installer located at http://nodejs.org/download/.Optionally, if you are using Linux, determine your Linux distribution.
Once you have found this, install Node for your specific distribution or Mac OS X, by following the instructions mentioned in the link https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager.
Once Node is installed, you can test npm by calling the following binary:
npm
You should see a trace similar to the following:
Usage: npm <command> where <command> is one of: add-user, adduser, apihelp, author, bin, bugs, c, cache, completion, config, ddp, dedupe, deprecate, docs, edit, explore, faq, find, find-dupes, get, help, help-search, home, i, info, init, install, isntall, issues, la, link, list, ll, ln, login, ls, outdated, owner, pack, prefix, prune, publish, r, rb, rebuild, remove, repo, restart, rm, root, run-script, s, se, search, set, show, shrinkwrap, star, stars, start, stop, submodule, tag, test, tst, un, uninstall, unlink, unpublish, unstar, up, update, v, version, view, whoami npm <cmd> -h quick help on <cmd> npm -l display full usage info npm faq commonly asked questions npm help <term> search for help on <term> npm help npm involved overview
To install a package in your current directory, you'll simply need to issue the following command:
npm install <package>
For instance:
npm install grunt
Note that at certain times, you may be interested in installing a package globally. To do this, you'll need to pass the -g
flag, as shown in the following command:
npm install -g <package>
You may be interested in the Node packages installed in your current directory. You can list them using the following command:
npm ls
To update all the packages in your current directory, issue a simple update command. This is shown as follows:
npm update