Anders Brownworth

Technology and Disruption

The New Face of JavaScript

By far the most popular language on the planet is JavaScript. Just about every computer has some implementation of it because it is included in almost every web browser out there. And as you might imagine, JavaScript has matured as a front-end language because of this pedigree.

But there is a promising new future for JavaScript. It was picked as the web's UI language because it is event based. JavaScript in the browser sits in a run loop and responds to events such as mouse-over and click events as they happen. But the other side of the web experience can benefit from an event based design as well.

Boiled down to it's simplest state, web servers just sit around in run loops responding to HTTP requests as they come in. Wouldn't it make sense to use the same event based design on the web server as well? There has been a growing trend toward event based design for some time. One example would be the migration away from thread-based web servers such as Apache's http server toward event based web servers such as nginx. But server-side development generally remained focused around "thread-centric" languages.

Then node.js came out. (yes, that is an entire paragraph)

Combining Google's V8 JavaScript engine and the missing server-focused routines, node.js presents a complete event-driven server-side JavaScript environment. For all the coders out there that already know JavaScript from their work within the browser, server-side coding is now only a short step away. For example, here is a complete webserver written in node.js:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World
');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/' );

Additionally, passing objects back and forth between the browser and the server becomes trivial because the server is written in the same language as the client. What is available in one is almost always available in the other.

Here's why this is very exciting to me. Back in the day I thought Java virtual machines might become the hardware agnostic "lowest common denominator" of the computing world. For a time it was on it's way toward happening. But probably because of the need to access things within proprietary operating systems such as Windows, the lowest common denominator of computing became the X86 architecture. Virtualized environments such as Amazon's EC2 could run Windows instances right alongside Linux and the game was over for the Java virtual machine.

But I see the whole race taking off once again. With node.js, the virtualized environment question is open again, at least within the web world. Why pay for a virtualized OS when all you need is a web server that likely sits there idle most of the time? Why take on the headache of operating system administration just to keep a fairly well defined web application running? I think JavaScript on the server is poised to redefine the "lowest common denominator" of web programming.

It could go back to Java but so many more people already know JavaScript, and there isn't a byte compile step so the workflow is smoother. Additionally, Java requires a good deal of foreknowledge about classes, paths and naming just to get started that JavaScript doesn't require.

Additionally, there is less of a need to let a proprietary system dictate the entire environment these days because almost everything is API accessible. The impact of this will take some time to show it's fruit but I think the tide will eventually prove irresistible.

If you haven't checked out node.js, give it a look. It is still young (particularly in things like binary processing and MVC frameworks with database access) but it is coming on strong. It heralds a new paradigm that I think will be important to follow.

Comments (0)

Leave a Comment

Name:
Location: (city / state / country)
Email: (not published / no spam)
Comment:

No HTML is allowed. Cookies must be enabled to post. Your comment will appear on this page after a moderator OKs it. Offensive content will not be published.

Click the ball to submit your comment.

To create links in comments:
[link:http://anders.com/] becomes http://anders.com/
[link:http://anders.com/|Anders.com] becomes Anders.com
Notice there is no rel="nofollow" in these hrefs. Links in comments will carry page rank from this site so only link to things worthy of people's attention.