The advantage of using Node.js - AkuCode


    This post is a getting started guide to Node.js, the server-side JavaScript runtime environment. Node.js is built on top of the Google Chrome V8 JavaScript engine, and it’s mainly used to create web servers – but it’s not limited to that. Node.js is a runtime environment for JavaScript that runs on the server.
    Node.js is open-source, cross-platform, and since its introduction 2009, it got hugely popular and now plays a significant role in the web development scene. If GitHub stars are one popularity indication factor, having 46000+ stars means being very popular. Node.js is built on top of the Google Chrome V8 JavaScript engine, and it’s mainly used to create web servers – but it’s not limited to that.

The best features of Node.js :
Fast 
    One of the main selling points of Node.js is speed. JavaScript code running on Node.js (depending on the benchmark) can be twice as fast than compiled languages like C or Java, and orders of magnitude faster than interpreted languages like Python or Ruby, because of its non-blocking paradigm.
Simple
    Node.js is simple. Extremely simple, actually.
JavaScript
    Node.js runs JavaScript code. This means that millions of frontend developers that already user JavaScript in the browser can run the server-side code frontend-side code using the same programming languages without the need to learn a completely different tool.
The paradigms are all the same, and in Node.js the new ECMAScript standards can be used first, as you don’t have to wait for all your users to update their browsers – you decide which ECMAScript version to use by changing the Node.js version.
V8
    Running on the Google V8 JavaScript engine, which is Open Source, Node.js can leverage the work of thousands of engineers that made (and will continue to make) the Chrome JavaScript runtime blazing fast.
Asynchronous platform
    In traditional programming languages (C, Java, Python, PHP) all instruction is blocking by default unless you explicitly “opt-in” to perform the asynchronous operation. If you perform a network request to read some JSON, the execution of that particular thread is blocked until the response is ready.
    JavaScript allows creating asynchronous and non-blocking code in a very simple way, by using a single thread, callback function, and event-driven programming. Every time an expensive operation occurs, we pass a callback function that will be called once we can continue with processing. We’re not waiting for that to finish before going on with the rest of the program. Such a mechanism derives from the browser. We can’t wait until something loads from an AJAX request before being able to intercept click events on the page. It all must happen in real-time to provide a good experience to the user.

"If you’ve created an onclick handler for a web page you’ve already used asynchronous programming techniques with event listener."
 
    This allows Node.js to handle the thousands of concurrent connections with a single server without introducing the burden of managing threads concurrency, which would be a major source of bugs. Node provides non-blocking I/O primitives, and generally, libraries in Node.js are written using non-blocking paradigms, making a blocking behavior an exception rather than the normal. When Node.js need to perform an I/O operation, like reading from the network, access a database or filesystem, instead of blocking the thread Node.js will simply resume the operations when the response comes back, instead of wasting CPU cycles waiting.
A huge number of libraries
    npm with its simple helped the ecosystem of Node.js proliferate and now the npm registry hosts almost 500.000 open source packages you can freely use.

Comments