O'Reilly logo

Node for Front-End Developers by Garann Means

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Getting Node Set Up

Depending on your environment, Node is easy to set up or very easy to set up. Node runs on Unix-compatible systems and, more recently, Windows. The former means it runs on Macs, Linux machines, and most environments you’re likely to be developing for. There are companies offering Node hosting with all kinds of great features like monitoring tools and deployment via version control tools like Git. However, you can also install Node on any server you can SSH into where you have the ability to create files and directories.

For purposes of getting something running, let’s assume you’re installing Node locally on a Mac. We’ll highlight the differences for Windows and remote server setup as we go.

Node and NPM

There are numerous ways to install Node itself, depending on your environment. The easiest option is to download one of the installers available for Windows or Mac from the Node website (these include npm, as well). You can also install it in one line using Homebrew or the Advance Packaging Tool. On any supported operating system, if you have Git installed, you can clone Node directly from the repository and build it yourself.

Since it’s fairly universal, let’s look at getting Node from GitHub. This assumes that Git is already installed and available.

$ git clone git://github.com/joyent/node.git
$ cd node
$ git checkout v0.6.6
$ ./configure
$ make
$ make install

All we’re doing is cloning the GitHub repository, running a configuration script, and then building and installing Node. Pay special attention to the third line, though, because we’re also switching to the branch containing the most recent stable version of Node. That changes frequently, so if you decide to install from the command line, check the Node.js website first to find out what the current stable version is, or use git tag to list available versions.

It’s no longer necessary to install npm separately, but if you need or want to for some reason, command-line installation is very straightforward. For all environments where npm is currently supported, the preferred method of installation is Curl:

$ curl http://npmjs.org/install.sh | sh

Note

npm is Node’s package manager. It maintains a registry of Node modules and allows one-line installation and version management of third-party packages. You can find modules in npm from the command line using npm search search term.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required