Building microservices with Dropwizard, MongoDB & Docker

Installing Node.js and npm on Mac OSX

Node.js is gaining a lot of speed and is an exciting new development framework. Here’s a quick overview of how to install Node.js on OSX along with npm, the package manager for node.

Update: There are now packages available for OSX and Windows if you prefer a one click install for Node.js and NPM. To install from source you probably know what you are doing but this article might help.

Install Homebrew

Homebrew is the package manager that Apple forgot. Written in Ruby it allows you to quickly and easily compile software on your Mac. Run following command in your terminal (⌘ space ).

ruby -e "$(curl -fsSL"

Install Node.js via homebrew

Once Homebrew is installed you can go ahead and install Node.js

brew install node

Easy! Now create a file called server.js and paste in the example server code

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(4000, "");

console.log('Server running at');

Save the file and run it from your console

node server.js

Now you can visit with your favorite browser and you are up and running with server side JavaScript.

At this point it is probably a good idea to consult the excellent Node.js documentation. This will help you understand what Node.js is and what it can do.

Installing npm

npm is Node’s package manager. It is now installed automatically with Node.js so there is no need to do a separate installation.

If you are developing anything in Node.js there is a good chance there is already a library to help you. It might be a module to connect to MySQL, a templating library or a utility library.

You can search for modules like this

npm search [searchterm]

So to search for underscore do this

npm search underscore

There is also a website for npm where you can search for packages.

Installing modules

Now we are set up we can install Node modules using npm. Express is a good place to start – it is a Node framework inspired by Sinatra.

npm install express

This provides a solid base to start developing with Node.js including jade the haml inspired Node tempting engine. There is more excellent documentation available for express too.

That’s it – Happy coding!

Let's Talk

Do you want to learn more about how I can help your company overcome problems? Let us have a conversation.