Learn nodejs in 2014

The year of the node

If you haven’t already (shame on you), it really is time to sit down and have a play with node.js. So that you have absolutely no excuses, I’ve put together a super quick start guide to kick you off.

Nodejs was first released back in May 2009 but has gathered huge momentum over the past year or so.

Super quick start

Install

Download the installer for your OS and install.

Create

Create a new directory for your app (optional) and a blank app.js JavaScript file.

1
2
3
$ mkdir nodeapp
$ cd nodeapp
$ touch app.js

Code

In your newly created JavaScript file, add the following code:

1
2
3
4
5
6
var http = require("http");
http.createServer(function(req, res) {
res.writeHead(200, {"Content-Type": "text/html"});
res.end("I know node.js!");
}).listen(4000);

Run

Ensure you’re in the directory of your app.js JavaScript file and run:

1
$ node app

Now visit http://localhost:4000/ to see your newly created node.js http server in action!

Packages

You’ll notice in the example above that we’re using http, which is part of the node core. There are over 50,000 3rd party packages available on the node package manager registry, that should keep you busy for the rest of the year :)

Happy new year!