So, this is my first blog and in this blog I would attempt to put down some stuff that I have understood or learnt or am learning or seem to have understood and putting together different pieces I have learnt from various sources also.
So let’s get started! Okay firstly a quick intro to what this Node JS is all about. And then I started to see how useful this could be. Node JS or simply Node is used to provide an awesome way to build network programs and those that could be scaled. Now you might ask why not PHP? And how is this Node going to be of any use?
This is one very satisfying explanation you’ll find –
What’s the issue with current server programs?
Let’s do the math. In languages like Java™ and PHP, each connection spawns a new thread that potentially has an accompanying 2 MB of memory with it. On a system that has 8 GB of RAM, that puts the theoretical maximum number of concurrent connections at about 4,000 users. As your client-base grew, if you wanted your web application to support more users, you had to add more and more servers. Of course, this adds to a business’s server costs, traffic costs, labor costs, and more. Adding to those costs are the potential technical issues — a user can be using different servers for each request, so any shared resources have to be shared across all the servers. For all these reasons, the bottleneck in the entire web application architecture (including traffic throughput, processor speed, and memory speed) was the maximum number of concurrent connections a server could handle.
So what does Node do and how is it any different? Instead of spawning a new thread for each connection each connection fires an event, as node is event-run. Node will never deadlock, and I/O calls are non blocking and asynchronous. Awesome ain’t it? For a fact, Facebook still uses PHP majorly and not Node!In case you’re wondering why, Node is a recent technology and changing the technology stack is not a risk that companies would probably be taking!
Okay, so if you’re still reading this. You might be interested in knowing more! Here’s the official site : http://nodejs.org/
There is documentation available on the site but you might not find the documentation quite useful if you didn’t know what to do with Node and what it’s meant for!
Okay cool! Let us check if you have node installed first. Type this on your command line :
You should now be seeing the version of node installed. Don’t have it installed? Follow the instructions given here for the installation and we’re set!
Cross check if it works?
Open the Node Shell from the command line :
$ node > console.log('Hello World'); Hello World
And now I suggest you go and read this. If you were a beginner like me, this is one perfect guide to make you an advanced novice in Node as the author says. 🙂 After this you should be able to do some cool stuff like writing an application that streams live twitter feed, maybe live feed about the location of visitors on your website if you own one!
And then once you are done, come back to visit my next blog which I hope to write soon where I’ll tell you about how I went on to use Socket.io (Web Sockets) and MongoDB(which is a non-relational database) with Node and what they are all about , why I had to use MongoDB and not a relational database like MySQL and how I used these to build an application.
P.S : Since it’s my first blog, and me being a beginner, criticism in any form(although constructive would be preferred ) and comments suggesting any improvements would be highly appreciated.
Update (4th June 2012) : To convince yourself as to why Node is cool and a comparison as to how bad writing networking code in other languages is comparatively. Check this out.