6 things you should know about Node.js

Node.js gives JavaScript coders an on-ramp to the server side, with easy access to tons open source code packages. Here are six high points courtesy of Joyent, the company behind Node.js

JavaScript is eating the world, with new tools and enhancements arriving at a breakneck pace. With Node.js, an open source runtime system invented in 2009 by Ryan Dahl, that reach has extended to the server side.

Node.js has become wildly popular, with coders everywhere using it to create APIs and build a new matrix of interoperability across the Internet. Joyent has been the chief sponsor of Node.js from the beginning. In this week's New Tech Forum, Ben Wen, vice president of product marketing at Joyent, outlines six things you should know about the phenomenon shaking up backend development. -- Paul Venezia

Node.js is a runtime system for creating (mostly) server-side applications. It's best known as a popular means for JavaScript coders to build real-time Web APIs.

But Node.js is not a JavaScript framework; indeed, several authors have written excellent frameworks specifically for Node.js, including Express.js, Restify.js, and Hapi.js. So what exactly is this phenomenon finding its way into Web applications, operating systems wrappers, microcontrollers, and robots?

At it's core, Node.js is a stripped-down, highly customizable server engine -- a proto-server, if you will -- because out of the box it doesn't do anything until you set it up. This proto-server processes in a loop, ready to accept and respond to requests. Any of those requests themselves may initiate other requests to some other part of the system, such as to read a file off of disk or to send a signal to spin a motor on a robot arm. That loop, known as the event loop, is the "runtime" part.

Node.js ships with workhorse connectors and libraries such as those relating to HTTP, SSL, compression, filesystem access, and raw TCP and UDP. JavaScript, already tuned for a Web browser's event loop environment for GUI and network events, is a great language for wiring up these connectors. You can snap connectors onto the event loop almost as easily as you can snap Lego parts together. Doing so lets you create a simple, dynamic Web server in just a few lines of JavaScript.

In short, Node.js is a runtime system that makes it easy to build a network or other event-driven application servers. Here are the six things you need to know about it:

1. JSON has won
JSON (JavaScript Object Notation) is a practical, compound, wildly popular data exchange format. JSON has enabled JavaScript developers to quickly construct APIs and foster interoperability at scale -- a key objective for Node.js coders. JSON's stark simplicity can be expressed in just five railroad parse diagrams, notably without the self-conscious preening of XML and its scheming friends (SOAP, XSD, WS-*, RELAX-NG, and their endless committee meetings).

JSON and JavaScript have reinforced each other's importance. Back in the early days of the Web, dynamic data in the browser had to be manipulated, filtered, and operated on by the only reasonably comprehensible non-plugin language available: JavaScript. Regardless of its original network-presentable format, data needed to be marshalled into a JavaScript object. The dependence on JSON for general purpose data description gave rise to document-oriented NoSQL databases such as MongoDB and CouchDB. It's all JSON all the time today.

2. JavaScript is everywhere
JavaScript is a quirky, object-oriented, C-like language. It's the only choice for developing applications in the browser, with a new framework introduced every week to woo developers. And with Node.js, JavaScript has spilled over to the server. Competing implementation teams have driven JavaScript interpreters forward, so that Google's V8 engine is respectably fast -- fast enough to reside at the core of Node.js.

JavaScript also has the internal capability to handle the event loop mechanism in a straightforward way. Other languages have this capability, which are used by their own evented systems. Python has Twisted and Ruby has EventMachine. But because of history, both of those event-loop systems come freighted with relatively easy ways to make a particular kind of performance mistake, while JavaScript remains relatively free of this peril.

JavaScript also runs across many OS environments, having historically had to support them in the browser. This, along with the libuv library to help abstract away some of the operating system differences, means that Node.js has a broad footprint.

But the biggest force for JavaScript's migration to the server side is human. Programmers have to do less mental context-switching between a Web browser and the server. There are even efforts to unify the environments between client and the server so that code can run equally well in either location, further simplifying the model and leading to increased productivity.

1 2 Page 1
Page 1 of 2
How to choose a low-code development platform