Installation
First, install Mac OS X and Xcode.
Install
Homebrew:
$ sudo chown -R $USER /usr/local
$ curl -Lsf http://github.com/mxcl/homebrew/tarball/master | tar xz
--strip 1 -C/usr/local
Install Node.js and Express:
$ brew install node
$ brew install npm
$ npm install express
Add the following to
~/.bash_profile:
export NODE_PATH="/usr/local/lib/node/"
You can verify that
NODE_PATH has been set correctly by running the
node program and inspecting
require.paths. You should see something like this:
$ node
> require.paths
[ '/usr/local/lib/node/'
, '/Users/kyle/.node_libraries'
, '/usr/local/Cellar/node/0.2.3/lib/node'
]
> require('express');
{ version: '1.0.0rc3'
, Server:
{ [Function: Server]
super_: { [Function: Server] super_: [Object] } }
, createServer: [Function]
}
Sample Program
Test it out. Put the following in a file named
test.js:
var express = require('express');
var app = express.createServer();
app.get('/', function (req, res) {
res.send('Hello World');
});
app.listen(3000);
Run It
Run using
node:
$ node test.js
And visit http://localhost:3000/ in your browser.
Up Next…
Here’s what we’ll be building in the next post: