Wednesday, July 22, 2015

Amazing facts about NodeDotJs


 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.




3. Sharing is encouraged

The ethos of the Node.js community is "share gleefully." It's frighteningly easy to share packages of library code -- technically, culturally, procedurally, and legally. The Node Package Manager is included with Node.js and has grown to a repository of nearly 50,000 packages, making it likely that another developer has already packaged up a solution to your  problem, or even some less common ones.

Node.js' namespace philosophy is essentially the absence of one, letting any author publish under an unused module name in the shared public repository. Sharing code under the MIT open source license is highly recommended in the community, which also makes cross-pollination of code relatively worry-free (and lawyer-free) from an intellectual property perspective. Finally, the community is highly engaged in binding interesting C libraries like computer vision (OpenCV) and the Tesseract open source optical character library. The latter, for example, makes possible weekend projects like Imdex that process images from the Web so they can be automatically searched for written content.




4. Node Package Manager works broadly

Speaking of managing library dependencies, the Node Package Manager deserves to be called out. Node Package Manager is the root of almost all deployment systems for Node.js and underlies the many PaaS (platform-as-a-service) providers for Node.js, actually making it somewhat easy to move smaller applications between providers. Its simple, dependable package management has let the Node ecosystem grow extremely well in recent history, to the point that the underlying public service now needs to scale to the next level.




5. 'Batteries not included' minimalism

Node.js applications and Node.js Core itself are broken down into small modules that are composed and shared.  Each package and tool can be scoped tightly and crafted to be manageable. These can then be baked together -- often without too much unnecessary kneading. The low-barrier, carefree nature of creating a module also encourages experimentation in the community, and there's quite a bit of overlap and experimentation in the package population. When executed well, each package typically handles one task (e.g. node-optimist.js: 'light-weight [command-line] option parsing').




6. Instrumentation

Finally, Node.js is well instrumented for production usage. What that means is that there are the tools to help bring an application to full production readiness and performance. As with any maturing technology, there are areas where more documentation, tools, and best practices could be helpful. But as Node.js heads towards its next major release, it's on fairly solid footing.





7. JavaScript on the server? What is this witchcraft?

For those of you geeks who don’t live in caves, skip to the next section. For every one else (noobs, I’m talking to you too), keep reading.
Okay, you know how server-side code is usually written in PHP, or Python, or (sigh) .NET? And browser-side code is usually written in JavaScript? Well, as it turns out, JavaScript is pretty awesome, and getting awesomer by the day. So some clever chap thought that it might be cool to write server-side code in JavaScript too, and that’s how server-side JavaScript was born.
It also turns out that the current standard JavaScript interpreter V8 (by Google, thank the Lord for them) is blazing fast, and makes JavaScript on the server around three times faster than Python 3 and around ten times faster than PHP.

But the real awesome thing about JavaScript on the server is that you can use the same code that you use in the browser (for example, form validation) in your server too. And, with a standard language like JavaScript being used in every level on the web, more libraries and plugins are being made every day so you don’t have to make your own session management system, or static file server, or user access system. You can get a solid web app ready to be deployed in half the time, and have more time for your kids, or friends, or WoW addiction, or whatever.



8. Coyote meets Roadrunner

Okay, let’s talk speed. How fast is Node compared to the alternatives?
From the creator’s presentation,
100 concurrent clients 1 megabyte response
node      822 req/sec
nginx     708
thin      85
mongrel   4
(more is better)
Seeing as nginx is the current heart-throb of the web developer’s server platforms (if you haven’t heard of it, just know that it blows Apache out of the water), Node claims high score by beating it.


7 comments: