Installing and Using Node Modules

After you install Node, you can use any of the hundreds of modules that people have packaged and made available. To do this use npm, the node package manager, which provides an automated way to download and install libraries and utilities. Previously, npm was installed separately from Node, but they are now packaged together. If you don’t have npm installed, make sure you run a newer version of Node.

If npm isn’t installed, you can still install it by following the instructions at http:///npmjs.org/. But first check that your Node install is up-to-date.

Installing Modules

By default, npm installs packages locally into a directory called node_modules under your current directory. When you build a server-side app, this makes a lot of sense so you can control exactly which versions of libraries are used. When you use Node from the command line, however, you often want to install certain modules globally, so the binaries are available wherever you are.

To install a module globally, use the --global option. One module particularly useful is the jshint module. This module, a slightly less opinionated derivative of Douglas Crockford’s JSLint tool, parses your JavaScript code and gives you feedback about what parts need to be tuned up.

To install this module, run the following command from the command line:

npm install --global jshint

This installs the jshint module and makes the binary accessible from the command line.

Hinting Your Code

With the jshint ...

Get Professional HTML5 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.