Taking Baby Steps with Node.js – Introduction

Taking Baby Steps with Node.js – Introduction

Like myself, you might have read an article somewhere about Node.js or heard it mentioned a couple of times during some talk. So I actually got curious and decided to start learning more about it.

So what is Node.js? I have to admit that I?m still trying to wrap my head around it. As far as I can tell, Node.js is an attempt (amongst others) to make JavaScript available on the server. Most people see JavaScript as the programming language for doing client-side scripting in a browser. Although this is the most commonly used scenario, things are slowly starting to change. Over the past couple of years, JavaScript (re)gained its popularity due to some innovative frameworks like jQuery, MooTools, ExtJS and others. Some NoSQL databases like CouchDB also started to make some good use of JavaScript on the database itself. A nice example of this are MapReduce functions that are written entirely using JavaScript. Therefore JavaScript on the server-side seems like a logical evolution for the language and its community. But there?s more.

Node.js makes use of the strengths of JavaScript like its excellent capabilities for doing event-based programming. If you?re used to working with DOM events in the browser, then Node.js will make you feel right at home. All JavaScript code on the server is run by the V8 JavaScript engine (yes, the one from the Google Chrome fame) and is also run in parallel, which makes Node.js very fast (although they claim).

There seem to be similar frameworks like Node.js on other development platforms as well like Twisted (Python), Jetty (Java) and EventMachine (Ruby). Node.js only runs on Mac OS X and other Unix-based systems like Linux. Windows is currently not supported, but you can work around this by installing Cygwin. If you don?t care about firing up Linux on a virtual machine, then you can follow the steps laid out by Matthew Podwysocki in his blog post on how to get started with Node.js on Windows.

There?s one thing that I feel is missing from Matthew?s post that I urge you to install as well. It?s a small tool called Npm. Npm is a package manager for installing non-standard modules for Node.js. Node.js already comes with a number of built-in modules for accessing the network or the file system, but there are a whole slew of other modules on GitHub or the Npm repository. The vast amount of open-source modules clearly proves that the Node.js community is a vibrant one and that they?ve been very busy providing more capabilities to the platform.

In order to install Npm, you first need to enable curl in Cygwin. If you already installed Cygwin and forgot to install this package, don?t worry. Just run the Cygwin installer again and select the required package. The packages you selected in a previous install will not be removed unless you explicitly unselect them from the list.

Now to install Npm simply execute the following command:

curl http://npmjs.org/install.sh | sh

There you go. Now you?re able to install as many open-source modules for Node.js as you like. The first one I?ve installed is a web development framework called Express. Getting this module is as simple as executing the following command:

$ npm install express

That?s it. As I mentioned earlier, I?m still figuring out this stuff myself. I?m more than happy to get some feedback and hear you thoughts about Node.js. I?ll probably be writing a couple of more blog posts about Node.js in the future as I learn more along the way.