How to Install Node.JS on your Mac OS X

NodeJS provides you a runtime environment for javascript without the browser. NodeJS is intended for use as a server-side Javascript runtime environment, but you will still be doing a lot of your development work locally on your Mac, so you will also need to install node on your Mac.

The associated package called npm (Node Package Manager) is also installed with node.
To install node on OSX  you can download a pre-compiled binary package which makes for an easy installation.
Firstly, browse available packages at http://nodejs.org/ , and  download the latest package for your OS X version.
Once the download is completed, open and install the package.
At the end of the install you are prompted to make sure that /usr/local/bin is in your path, double check you have it by opening the Terminal app and typing:

echo $PATH

If you don’t already see “/usr/local/bin” in the path, add it in either .bash_profile or .bashrc in your home directory.

Check that node was installed correctly by opening a node javascript REPL (Run-Eval-Print Loop) session:

$ node
> console.log('hello node');
hello node
undefined
>

To exit the node session just hit ‘control’ + ‘c’ twice.

Upgrading node

If you have an earlier version of node you can just download the latest version and install to upgrade it and it will overight the previous version.

Installing Packages for Node

There are many packages for node, managed using the command npm.
To see a complete list of node packages run:

npm search

This will return an exhaustive list of available packages.

To install a package run npm install, like this:

npm install express

To list installed packages run

npm ls

To upgrade npm packages

npm update

To upgrade node.js itself on OSX just download and install the latest from node.org, or install the node updater package n using npm

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s