What is Node.js?

What is it?

NodeJS brings the Javascript programming language to the server. It enables people to write websites, services and other server side functionality. Under the hood, Node uses Google’s speedy V8 Javascript engine (currently used in their Chrome browser) with additional API’s to handle all sorts of useful server side functions such as handling HTTP requests, TCP sockets, cryptography etc. People have written an already impressive array of modules for handling connections to databases and API’s of all kinds.

Why is it exciting?

Being able to author web apps in Javascript may be exciting to people who are already familiar with authoring front end functionality – it allows people to potentially share code between the front end and back end, and to keep consistency between all their code. However, since NodeJS still requires a large amount of work to do standard web hosting / page serving duties, I think NodeJS is far more attractive for writing specialized kinds of applications that sit on the server rather than the sorts of things a front end person might write. This includes back end processes, realtime, socket level applications like chat servers or doing expensive operations involving making multiple API calls to other servers or databases. What makes NodeJS attractive for this? Node’s API is built from the ground up to make all time consuming operations asynchronous (ie, non-blocking). While many languages offer the option of doing some things asynchronously, NodeJS really gives you no choice but to handle operations using event callbacks. This makes it an extremely good choice for certain types of operations. Consider PHP which really has no asynchronous event handling. If you need to make 10 database calls or make 10 http requests, then you have to wait for each one to finish before the next one starts processing. This ends up wasting a lot of CPU cycles, because those processes typically aren’t doing anything – they are waiting for a response from another server or system. With NodeJS, all of those requests happen at the same time. This means that the time it takes for a NodeJS script to finish would be as long as the longest request takes. With PHP, it’s the sum of the length all the requests.

Why would I want to use it?

NodeJS’s API is still fairly low-level. Setting up a full web server stack takes a decent amount of work and while people have started authoring solutions for almost every problem a web developer may face, many of those solutions are still in their infancy and lacking features. Time will tell whether NodeJS can attain the kind of ease of use that we get from something like PHP or the enterprise level security and reliability something like .NET or Java. Where NodeJS is exciting is in building some of the ‘glue’ between the front end and the back end. It can be useful for helping to optimize slow processes or developing new kinds of web services that don’t exist yet because they would be too slow or cumbersome to develop using other tools. Node is also finding some use as a way to author cloud based services.

Since NodeJS is using the same Javascript engine as Chrome, a significant amount of time has already been spent optimizing it and debugging it. That also means that NodeJS benefits from any future improvements that Google makes on V8 for Chrome.

Personal Experience

I’ve only been using Node for a couple weeks, but my initial experiences have been very favorable. My first Node project involves interfacing with the Facebook API and processing large amounts of data. I already had a working solution in PHP, but wanted to see what kind of performance gain I would get from using NodeJS. This is a perfect scenario for Node, since each Facebook call can be parallelized by using asynchronous NodeJS calls. The same goes for any calls to our database. I’m currently seeing a speedup of nearly 10x just from porting my code from PHP to NodeJS (doing no other tricks). The Node solution will allow for better scaling and lower memory usage. I was able to use two community made modules in the project – the node-facebook-client and SequelizeJS for talking to the database.

Another nice thing about using Node is that since it’s Javascript, it meshes nicely with many existing API’s (like Facebook’s) that use JSON as the preferred way to exchange data. Parsing and encoding data takes no effort. Something I hope to look into more is MongoDB, which stores data in a JSON friendly format as well. Having all your data in the same format means less time spent having to think about how to store and retrieve it.

Leave a Reply

Close Modal

Contact Archer

Close Modal

We know you're still using an older version of Internet Explorer. Do you know how much mind-blowing stuff you're missing because of this?

Save yourself. Upgrade now.
We'll help you...