What You Need To Know About Node.js

Started by ReadWrite, Nov 07, 2013, 11:31 PM

ReadWrite

   

Node.js, a framework that's been around since 2009, is making a big impact in web programming circles.

With disciples in Microsoft, Yahoo, LinkedIn and PayPal, developers have not only heard of the merits of Node.js, but they're either using or learning it now.

See also: Why Developers Should Pay Attention To Node.js
 Consumers may have heard that Node.js as "responsive" or "lightweight," but might not know why. Here are a few of the reasons Node.js is going to be the backbone of your next website, app or API.

The Web's Use Case Has Changed In the old days, the Internet used to be about consumption. Users would passively read, watch and download content. Chat was done on message boards or blogs, not in real time.

But as social media has increased in popularity, today's users want to be able to receive instantaneous feedback over the Web. Chatting, gaming and collaboration now take place in real time. Even more significantly, this is happening on an imposing scale with up to millions of users interacting on one site at one time.

Software developers know the Web wasn't built for this. Real-time response means that each users' client would be constantly querying the server, making for sluggish, inefficient response times.

Node.js To The Rescue To make the Web responsive, communications can't start from the client side. Instead, servers need to push data to clients instead, and only when there is data to push. If they're constantly pushing data, it'll be an equally tedious process.

See also: Wait, What's Node.js Good For Again?
 This is what Node.js does. Node.js runs JavaScript by leveraging V8, Google's fast JavaScript engine designed for Chrome. This allows Node.js to create a runtime environment that pushes JavaScript from the server to the client quickly. V8 translates JavaScript into native machine language, instead of working overtime to interpret it as bytecode, giving Node.js its speed.

This speed, combined with asynchronous programming, are the twin powerhouses that make Node.js so responsive.

The Benefits of Asynchronicity Ryan Dahl, inventor of Node.js, said he was first inspired to create the framework in 2009 after watching a loading bar on Flickr. The site kept querying the server in order to display how much had downloaded. Dahl thought it'd be faster if the server pushed updates to the client without the client having to begin every query. The same way that when you're listening to another person talking, you're not constantly sending them a signal to convey that you're listening to them. You simply receive the information.

In other words, human communication isn't like a programming language. It happens chaotically, out of sync, and it isn't parallel—I don't have to wait for you to reply before I can talk again.

Node.js works in this same asynchronous way. It uses a function called the Event Loop that ensures that data isn't constantly being queried for, but simply transmitted when it exists. It's kind of like a holding cell for communication. So while the Event Loop is handling asynchronous tasks, Node,js can continue running the program normally and leave out the heavy lifting. It makes Node.js very good at idling when there's nothing to do, instead of constantly querying for more information.

This means that developers can use Node.js to build applications that scale to millions of users. Real time communication is managed by the event loop without taking up much memory, so developers can spend more time working on the functionality of the app than they might spend worrying about the app getting clogged with too many queries.

Learning Node.js Unless you're a developer, you'll never need to know how to use Node.js. But if you're considering basing your next app on it, you might want to get acquainted with it.

Typically, Node.js is used for Web-based gaming and communication apps, both of which require lightweight, real-time response for large numbers of users.

As Web engineering company Toptal states, "Node.js is not a silver-bullet new platform that will dominate the web development world. Instead, it's a platform that fills a particular need. Where Node really shines is in building fast, scalable network applications."

As Node.js continues to catch on, it won't be hard to find people who know how to use it. Since it's based on popular JavaScript, it has an extremely low learning curve for people who are already programmers.

The best place to start is NodeBeginner.org, which offers a free and thorough 21-page tutorial.

Image courtesy of Node.js.