We will need to install a couple of additional tools to test and build our application. The foundation for this will be Node.js and NPM, the node package manager. Node.js is a platform built on top of V8, Google's JavaScript runtime, which is also used in Chrome. You can also build server-side, networked applications with Node.js, but here, it will only power our test and build the system. For now, think of it as a way to run the JavaScript code outside the browser. NPM is the package manager for Node.js, which makes it quite simple to install additional functionality. It comes bundled with Node.js.
The easiest way to install Node.js is to follow the instructions at http://nodejs.org.
On a Mac, you could either run the aforementioned installer or you could use Homebrew, a package manager for many open source libraries.
More information on Homebrew can be found at http://brew.sh/. Run the following command in the Terminal after installing Homebrew:
# brew install npm
The previous command will automatically install Node.js as a dependency of NPM if necessary.
Shell commands will run in a Terminal window. If you haven't used the Terminal before, go to the magnifying glass icon in the upper-right corner of your screen and type Terminal
. You will need to open a new window after the installation is complete in order to run Node or NPM from a Terminal window.
On Windows, the easiest way to install Node.js is to run the Windows installer from http://nodejs.org. This installer, by default, now also installs NPM.
Command-line commands will run in the Windows command prompt. On Windows 7, this is available by clicking on the home button and entering cmd
in the search box. You will need to open a new command-line window after the installation in order to be able to run Node or NPM from the command line.
On Ubuntu, there are two ways of installing Node and NPM, as follows:
Preferred: download the source package from the Node.js web page and build it yourself (this may take a few minutes with a lot of output). This way, you are guaranteed to have the latest version. For this, perform the following steps:
Uncompress the package.
Open the folder in the Terminal.
Inside the directory, run the following commands:
# ./configure # make # sudo make install
You may have to install G++ first:
# sudo apt-get install g++
You can also install NPM through Ubuntu's package manager by running the following command in the Terminal:
# sudo apt-get install npm
This will install Node.js as a dependency of NPM as well. Afterwards, if you want to upgrade NPM itself, then run the following command:
# sudo npm install –g npm
While this approach works, you may get an outdated version; so, the first approach is generally recommended.