• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Notes to Self

  • Aviation Weather from NOAA Plugin
    • KZZV
    • Bad Shortcode
    • Simple Metar
  • Meetings

Mark Chouinard / June 11, 2013

Getting Started with Node.js on Mac OS X

Straight from here. Thanks, Jason.

This is a step-by-step process on installing Node.js on Mac OS X. There are several “getting started” tutorials online but I didn’t find much on Mac OS X. The ones I did find were a little confusing since I had no previous experience with Node.js. At the time of this tutorial, I’m running OS X 10.8.2 also known as Mountain Lion.

Installation
There are several different installation instructions using Homebrew and other methods but the easiest is to install the Mac Installer Package straight from Node.js. Once it is downloaded, open the package and follow the instructions. The default installation path is /usr/local/bin/node but you can change that to the path of your choosing. The great thing about the Mac Installer Package is that it also installs Node Package Manager (npm) which, in the past, used to be a separate install. The default installation path for npm is /usr/local/bin/npm.

Install Verification
To verify that Node.js was installed successfully, open up terminal and execute the following:

node -v

The output should look like v0.10.0 or whatever version of node is current at the time you install it. The same thing can be done to verify npm.

npm -v

Creating you first Node Project
Now you can create you first node project and confirm that node is working correctly. You can use the node sample project provided on the Node.js homepage. Create a new file called example.js and add the following code:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

You can start the server by running the following command:

node example.js

Note: example.js must be saved under your user directory. If not, then you need to provide the entire path or change it using cd.
To verify that its working, open a browser and go to http://localhost:1337/. You should see a “Hello World” message.

Kill the server
To kill the server enter Ctrl-C (Ctrl + C) in terminal.

Thats all there is to it. You have successfully installed Node.js and ran you first node project. I have to admit after reading several online tutorials, I thought installing Node.js and creating my first project was going to be harder than this. The Installer Package really makes this an effortless process. Stay tuned for more Node.js tutorials.

Filed Under: Command Line Tagged With: Node.js, OS X

Primary Sidebar

Post Archives

  • June 2024
  • December 2022
  • July 2022
  • December 2021
  • October 2021
  • June 2021
  • February 2021
  • October 2020
  • September 2020
  • August 2020
  • March 2020
  • February 2020
  • December 2019
  • September 2019
  • June 2017
  • May 2016
  • April 2016
  • March 2016
  • September 2015
  • August 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • June 2013
  • May 2013
  • April 2013
  • February 2013
  • January 2013
  • December 2012
  • January 2011

Footer

Copyright © 2025 · machouinard · Log in