Home > Mac, Web > Installing node.js on Mac OSX

Installing node.js on Mac OSX

Node js

Node.js

I recently installed node.js on a Mac running OSX 10.7.2 and these were the steps I followed at the command line.  Git and Xcode were already installed on the machine so this assumes they are already present.

  1. git clone git://github.com/ry/node.git
  2. cd node
  3. ./configure
  4. make
  5. sudo make install

You can test that node is installed by running a simple program such as:

var http = require('http');
http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Node.js has arrived.\n');
}).listen(1337, "127.0.0.1");
console.log('Up and running at http://127.0.0.1:1337/');

You can run this code by saving it as something like testing-node.js and then entering the command:

node testin-node.js

That’s it. Node.js is now up and running on port 1337 !

PS: stop the server with ctrl + c

 

Categories: Mac, Web Tags:
  1. Harish
    March 12th, 2013 at 18:08 | #1

    Hi,

    Great article. Really helped a lot. Please explain more in detail about
    1 ./configure & make commands. I would like to know what they do.
    2. Is there any specific folder that node likes to read the js file off of ? or can I have js files anywhere and just run “node” command from that directory?

    Thank you,

    Harish

  1. No trackbacks yet.