HTML and CSS Reference
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.
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 glob-
ally, 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.
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 node module installed, you can now run jshint from the command line to run a quick syntax
check on your code. JSHint can discover errors such as missing semi-colons or odd structures that wouldn't
necessarily prevent your code from running, but might lead to tough-to-find bugs down the road.
To run jshint on a file, run the command at the command line followed by the name of the file. For ex-
JSHint generates a list of descriptive warnings, including line and column numbers, which can help you im-
Uglifying Your Code
When you deploy your game for players to play, you want it to load as quickly as possible. One way to cut down
ables and parameters to significantly reduce the size of the code. Using the Alien Invasion game from Chapter 3,
“Finishing Up and Going Mobile,” running engine.js and game.js through the uglify-js minifier reduces
the size of the code from almost 19 K to just more than 11 K, a compression of more than 40%.
To install uglify-js, install the module via npm globally:
npm install --global uglify-js
The uglify-js binary takes only one file, so if you want to merge multiple files into one (as you should), you'll
need to concatenate them separately. On Windows you can run the following:
type file1.js file2.js > all.js
uglify-js all.js > all.min.js