Why to consider Node.js for your mobile web apps?

NodeJS

We at langoor.mobi are really excited to part of the mobile revolution. This is the time when leading companies in every domain are facing questions about their future earning streams on the basis of their mobile presence. This is the era when people are realizing that a bad mobile experience can damage a company’s brand.

Let’s get to the point. Mobile is growing. So is HTML5. Together they have triggered the rise of “Real time Web” and real-time web requires real-time technologies like Node.js.

Node.js – “In the focus”

Prime-time companies have relied on Node.js for their mobile solutions.

LinkedIn is a prominent user. Their entire mobile stack is built on Node.js. They went from running 15 servers with 15 instances on each physical machine, to just 4 instances – that can handle double the traffic!

eBay launched ql.io, a web query language for HTTP APIs, which uses Node.js as the runtime stack. They were able to tune a regular developer-quality Ubuntu workstation to handle more than 120,000 active connections per node.js process, with each connection consuming about 2kB memory!

Walmart re-engineered its mobile app to use Node.js and pushed its JavaScript processing to the server.

So, what is this Node.js and why has it been the primary choice of the big shots?

Node.js and JavaScript

Node.js is a server-side development framework that makes use of event-driven non-blocking I/O and prides itself on:

  • using JavaScript, the language of the web.
  • being able to bridge the gap between the front-end and server-side architectures.
  • supporting code reuse at every level – client, server and even database (MongoDB).

OK – you might be wondering “JavaScript, huh? I don’t know..”.

“When I first heard about Node.js, I may well have scoffed. I don’t tend to scoff a lot, but using JavaScript to run a server engine seemed a bit like circumnavigating the globe in a swan-shaped paddle boat.” – Whit Nelson, Mightybytes

One of the primary reasons that Node.js is getting traction is that developers are used to the asynchronous programming style with JavaScript, already. Even backend developers play with a bit of JavaScript from time to time.

Yes, JavaScript isn’t the perfect language but neither is any of the other languages. Every language has its pitfalls and that is why someone takes pains to put together a set of best practices. Once you are out of the browser world, the worries regarding backward compatibility vanishes and the good parts shine through. From what my experience with JavaScript has been, its functional abilities are better than most of the other languages.

Open Source

Node.js is open-source and has a strong and passionate community. It is the second most Popular Starred repository on Github. NPM is the node.js package manager, and as the name implies – is used to install node programs. There are thousands of developers contributing modules to NPM and providing incremental updates and additions to Node.

Though Node.js is relatively new – it has some awesome frameworks that help reduce the load to a great extent. Though I have been involved in Node.js app development for a while now, but I’m still not capable of keeping up with the latest and greatest additions to the Node family myself. I have primarily used Connect, Express and Socket.io. To see a list of some renowned and widely-accepted frameworks, visit this link.

Performance and scalability

Node’s speed and scalability comes largely from its asynchronous programming model. Traditional web application software is based around the request-response cycle. A request arrives; the application routes it, builds up a response by consulting databases, disks, APIs, etc., and finally sends the completed response back to the client. Node is similar in design to and influenced by systems like Ruby’s EventMachine or Python’s Twisted. Node takes a step further and presents the event loop as a language construct. Node simply enters the event loop after executing the input script. Node exits the event loop when there are no more callbacks to perform. This behavior is like browser JavaScript — the event loop is hidden from the user.

Node’s specialty is high-concurrency, real-time applications: anything where you need to have a large number of users connected at the same time. But Node can be used to serve any website or application, and it will do so with its characteristic speed and efficiency.

Page Rendering

Node.js allows you to tune page rendering between client and server based on the network. Server-side rendering is no longer fiction! Maybe you are already using frameworks like YUI or jQuery to generate views in the front-end based on the JSON/XML data received from the backend. Now, you can use the EXACT same code to do rendering on the server. YUI3 is now available full-fledged for Node.js, thanks to enormous amount of time put in by Dav Glass! To know more about how can you optimize client and server side rendering, watch this video by Matt Taylor.

Push Notifications

It’s possible for NodeJS to interface with the various push notification systems available on each platform, or to use something like SocketIO to provide real-time communications between client and server. This article is a particularly good read on the implementation of a push notification server Node.js and a simple push notification server.

Resources

There are tonnes of resources to learn Node.js. I’ll list a few which will help you get started:

Conclusion

Node.js has not reached v1.0 yet – but is surprisingly very stable and widely adopted.  As mentioned earlier, Node.js is not the only tool in the market to that does non-blocking I/O. There are quite a few – but what differentiates Node from the rest that it has a vibrant community which has been working around asynchronous, event-driven application logic, right from day one.

What I would want people to do is to go give Node.js a fair try! Talk to me if you face issues, be active in the Node IRC channel. Talk to people who have already done it. Node.js is a relatively young server platform and definitely isn’t a silver bullet to replace all existing server platforms. If you need a light weight, efficient and scalable platform to provide services for your mobile app, Node.js will likely be a great choice.

Let me know your thoughts in the comments section below. Happy Node-ing!

Image courtesy of xtremelabs.com
Share
  • lalit chandnani

    Nice Article..

  • http://www.facebook.com/deeps.pathak Deepak Pathak

    The Node.js technology stack, coupled with a MVC framework like Geddy or Express and a NoSQL database engine like MongoDB makes a perfect, low on resource solution for real-time web.

    While working on Node.js for quite some time now, I agree that its popularity has increased exponentially over last 6 months or so, and continues.

    • http://twitter.com/rakeshmenon13 Rakesh Menon

      Yep. Also of late, I have been playing around with the Meteor framework. It’s brilliant! It is built on top of node.js and makes use of MongoDB with DB access on both server and client side!

      • gaurav

        ok