Code Smoothie

Why NodeJS?

A concise look at why I believe NodeJS is the future of all languages

NodeJS is becoming increasing popular. The recent StackOverflow survey showed that Node is the most popular platform, in terms of “wishing to learn”.

There are many reasons for this

Most of this pertains the JavaScript language itself.


Fast development

For starters, JavaScript is incredibly easy to write. Compare a simple “Hello World” in JavaScript to one with Java:

JavaScript

console.log("Hello World!");

Java

public class HelloWorld {
    public static void main (String[] args) {
        System.out.println("Hello World!");
    }
}

JIT (Just in Time) Compiled vs Compiled

In Javascript, one doesn’t have to worry about compiling the code. In fact, you can even edit the code that is running. This leads to my next point…

Dynamicity & Power

JavaScript is incredibly dynamic. Functions are variables. Objects are easily created with literal syntax: var stuff = {key: 'value'}; This skips the new syntax. All this adds to more flexibility and power.

Dependency Injection

It’s really easy to pass dependencies with Javascript, no matter the type. Need to pass a callback? Just pass the function in. (Not function name. The JS engines automatically pass it in as reference for you.)

Passing a bunch of things in is still really easy.

Let’s look at a jQuery ajax example:

var xmlDocument = [create xml document];
var xmlRequest = $.ajax({
  url: "page.php",
  processData: false,
  data: xmlDocument
});
...

(Krasimir writes more about DI design patterns here)

Super easy!

No need to declare a bunch of global variables!

Scope

JavaScript scope is admittedly complicated. Every block, including functions opens a new scope, and variables declared with var are visible in that scope.

But when we introduce closures, things get complicated (but again, really powerful).

Deployment

Deploying JavaScript is really easy. All you got to do is upload the files.

JavaScript is compatible with tons of platforms, including the browser, server, mobile devices, and more.

The implication is that not only do full-stack web developers have to learn only one language, JavaScript code can be shared across the server and client!

(A popular platform that implements this idea is Meteor)

Yes, stop and think about it: this point wins the whole thing by itself!

Performance

But not only does JavaScript run anywhere, it runs anywhere natively and quickly. JIT compilation is much, much faster than interpreting, which PHP does. NodeJS performance, therefore, is significantly better than PHP.

Also, Cordova and other tools allow it to run natively on mobile devices.

Conclusion

So why do you think NodeJS is so popular, and do you think it deserves this popularity?