Installing Node.Js On OS X 10.6

February 8th, 2010
 

Updated May 7 2010, With Version 0.1.94 From GitHub

Node.js is evented i/o for Google’s V8 Server Side JavaScript engine. For me . . . node.js means I can write apps that can handle tons of requests without having to learn/think about threads & locks (all I know about threads is that they are scary and involve big books from O’reilly).

As a front-end developer the node.js approach is fantastic because I already think in terms of events and I love writing code in JavaScript.

Installing node.js on OS X is super-easy and the documentation on the node.js site is great, but I figured I would write a step-by-step for OS X since I had just installed it for the first time. The node.js install includes Google’s V8 JS engine so no need to worry about installing that.

Download and Install Node.JS

Get node.js from either github or download from the node.js site. If you need GIT for OS X you can grab the code from google http://code.google.com/p/git-osx-installer/ and follow GitHub’s install instructions.

http://github.com/ry/node

http://nodejs.org/#download

Build & Install

Build node.js by following the instructions in the readme or just run:

1
2
3
 ./configure
 make 
 make install

At this stage you may get an error about a missing compiler (I did). This can be caused by outdated developer tools or completely missing developer tools. In my case I did not run the Xcode install from my Snow Leopard Disc when I upgraded. So if you get this error grab your Snow Leopard DVD, put the kettle on, and run the Xcode installer.

You may also get a permissions error running make install, in this case just sudo make install.

Test Server With Hello World

Copy the test server code from below (taken directly from http://nodejs.org):

1
2
3
4
5
6
7
8
9
10
11
var sys = require('sys'),
    http = require('http');
 
    http.createServer(function (req, res) {
        setTimeout(function () {
            res.writeHead(200, {'Content-Type': 'text/plain'});
            res.end('Hello World\n');
        }, 2000);
    }).listen(8000);
 
sys.puts('Server running at http://127.0.0.1:8000/');

Run it with:

node example.js

And go the the following url in a browser:

http://127.0.0.1:8000/

You should see the text “hello world”. If you do congrats, node.js is installed!

 

6 Responses to “Installing Node.Js On OS X 10.6”

  1. Karl Tiedt says:

    With recent updates to node.js you need to
    s/sendBody/write and s/finish/close
    to make this work again

    Thanks for the ‘how to’!

  2. Benjamin says:

    Thanks for the heads up. Node.js is changing a lot quicker than I thought. I will update the article after I try installing the latest version. I will also note what node.js version number the instructions are for (should have done that in the original article).

    Thanks!

  3. Benjamin says:

    I just installed node on a fresh mac and updated the docs. There was a slight change to the example.js file but other than that everything should work.

  4. JQ says:

    after you download it, where are you suggesting we unzip the file to?

    (I always have this question when it comes to git projects; sometimes I think the smart folks assume us dumb folks know more than we do!)

  5. Benjamin says:

    Well this depends a lot on how you like to work. I have a “projects” directory and I check everything out to that. So on my os x machine i have:

    ~/projects
    ~/projects/project1
    ~/projects/project2

    Usually each project (if code) is a git project. Where you “check out” has a lot to do with how your computer is setup and where your organize things. There’s no real rule.

    Hope this helps!

  6. truedat says:

    I recommend to pull from a tag, not the master branch. I am working off tag v0.2.0.

    Then ./configure –without-ssl –without-snapshot

    Apply this patch to build. This will pass all test cases except for those testing openssh and cyrpto. I am sure you can get ssl work but like building any of this OSS it is usually easier to start by turning off a few features with the build. I am not sure why V8 is built in a non-standard way, with so little attention to keeping the build working across platforms and architectures, between releases. Anything that uses Scons I have found has these issues.

    diff –git a/wscript b/wscript
    index 7f024bf..0bd5f5d 100644
    — a/wscript
    +++ b/wscript
    @@ -571,7 +571,7 @@ def shutdown():
    # HACK to get binding.node out of build directory.
    # better way to do this?
    if Options.commands['configure']:
    - if not Options.options.use_openssl:
    + if Options.options.without_ssl:
    print “WARNING WARNING WARNING”
    print “OpenSSL not found. Will compile Node without crypto support!”
    elif not Options.commands['clean']:

Leave a Reply