No Batteries Required - Home
Node to Self: Get Ready for Asynchronous Programming - Part I
Ray Kahn
APR 22, 2015 10:01 AM
A+ A A-
A couple of years ago one of my team members introduced me to Node.js. His pitch, if I can call it that, was that Node.js is a much better web platform as it’s based on Chrome’s JavaScript run time and does not come with the usual baggage associated with legacy systems like Apache (A Patchy Server - as he called it). But I think the selling point for me was the support for RESTfull API. At the time I had no idea how to program for asynchronous framework. Yet I made it my mission to to have real-life experience using Node.js, which I did by building a three tiered publishing platform.

What is Node.js

Node is defined as “an asynchronous event driven framework, Node.js is designed to build scalable network applications… many connections can be handled concurrently. Upon each connection the callback is fired, but if there is no work to be done Node is sleeping.” This explanation is not too difficult to grasp but of course the devil is always in the details: “many connections can be handled concurrently. Upon each connection the callback is fired”. 

Node.js is quite different from the frameworks many developer and practitioners are used to. So much so that getting your mind around it is an arduous and painful proposition, at least it was for me. And the difficulty comes from its asynchronous nature. Traditional frameworks are based on procedural execution: a statement is executed while the framework waits for the completion of that statement before the next statement is executed. Not so with Node.js. Depending on the statement, Node.js executes statements in non-blocking manner - commands are executed in parallel. Node.js is an event driven framework which uses callback to signal that a task has been completed. 

The key term with Node.js is non-blocking - I/O operations are concurrent and thus many thousands can be spawned without the thread context-switching cost. This makes concurrency a very easy task as long as you remember that call backs are the key to signaling to the main thread that the operation has completed. But running and operating on a single thread is also a draw back to Node.js as framework effectively can’t scale for multi-core CPUs natively (pm2 is one of the modules which fixes this shortcoming of the framework).

What’s Next

In the coming weeks I will walk you through installing Node.js on your Linux/Mac servers (I don’t use a MS computer and as a result all my exercises will be using my MacBook Pro). In the meantime if you are interested you can start by visiting the sites mentioned in the “Resources” section to learn more about Node.js. 

As I mentioned at the beginning of this thread I created a publishing platform based on Node.js, Express, and MongoDB running on AWS Ubuntu servers. In the future threads I will walk you through all the steps necessary to install, configure and build the same eco-system which I did for my publishing platform. What you need is a good knowledge of JavaScript, CSS, HTML, mongoDB (this is a noSQL database) and, of course, have fun doing all of that. 



Node School:


[%= name %]
[%= createDate %]
[%= comment %]
Share this:
Please login to enter a comment: