Stellar Code

Full-stack Web Development with JavaScript (MERN stack)

Why Node.js is Powerful

Back End

Listen to this blog post:


The What

Node.js is a very significant framework in Web development that marked a milestone in server side development. It birthed the ‘JavaScript everywhere’ buzzword because it brought with it the ability to use JavaScript not only in a browser (front-end/client-side) but also on a machine (back-end/server side). This means JavaScript which only enabled user interactivity in websites and web apps could also provide an unlimited set of utilities. From the official node.js documentation website, the following definition is provided:

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world

 

Essentially, node takes what makes JavaScript run in the browser, out of the browser into a computer environment. This means JavaScript can even run in your laptop machine. The Chrome V8 engine is essentially an interpreter written in c++ that converts JavaScript code into machine understandable code (0’s and 1’s). Node makes use of this on a machine.

 

The Why

Taking cues from the official documentation of node, I will explain with four points why it is powerful and better than existing programming languages.

Node.js uses an event-driven, non-blocking I/O model

Source: webapplog.com

This is a feature at the core of node’s power. I/o refers to Input/Output, it describes the way computers perform operations with the external world, operations such as reading or writing to a database, HTTP requests etc. The I/O operation is the darling of network applications but have traditionally been ‘blocking’. Blocking languages like PHP or Java did I/O operations in a sequential/synchronous order but Node.js’s I/O operation is event-driven/asynchronous. Essentially node.js does not just run code line by line but when it encounters an operation that could take time, it kickstarts it and goes to the next statements of code while waiting for the operation to be completed whenever it would. A callback is used to state what should happen after such operations have been completed.This makes node faster than other programming languages. More on this in a future post.

A real life illustration of this is how different coffee shops operate. Some shops let customers line up in a single queue and then attend to them one after the other. No customer is attended to until a previous customers drinks have been prepared and served. This is a blocking model and is wasteful because more resources such as waiters will be needed. However, there are other coffee shops that have you say what you want and then you go off to sit and while your order is being prepared, the next customer is attended to. This is a non-blocking I/O. After your coffee has been prepared, it is delivered to you. In this approach, less resources such as employees are needed. In computer, resources would be the CPU power. Node can run on less powerful CPUs while other the blocking approach may require more CPUs.

Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world

Secondly, the community around node.js is the biggest in the world, providing open source packages for almost every programming utility you can think of. This is a great because as a developer, you could take advantage of libraries or plugins that have already been written to build your project.


Also published on Medium.


Emmanuel Yusufu

Web Developer. Learning enthusiast.