Okay let’s start by the definition — NodeJs is a single threaded, concurrent asynchronous programming language which provides non-blocking I/O and event-driven architecture and was initially written by Rayn Dahl in 2009.
Yes, even I didn’t understand a word of it when I read it for the first time. So let’s break it down.
NodeJs became a boom when it was introduced to be a run-time environment which means something which could only be compiled on the browser to something which could run on a standalone machine. Woah !!!
Now from being just a scripting language which is used to make only web applications to write all the backend code, now NodeJs provides developers a comfort of developing a frontend and backend in a single language 😀😀.
NodeJs has a very big advantage of speed, versatility, performance, scalability, and non-blocking I/O model as compared to other conventional server-side programming languages like c#.
Also, NodeJs framework supports cross platforms, If you know java you can obviously relate here.
Okay, but how does NodeJs has managed to be so great 😕??
Because of its great architecture, that’s because it is single threaded and non-blocking I/O model.
Yes, You read it correctly it is single threaded… then how does it a non-blocking I/O system?
To answer this question we need to understand what is event-loop?
Event-loop is one of the most important features of NodeJs framework which also explains how exactly the code gets executed in the Node environment.
Event Loop comes with the stack, some web APIs and callback queue. Event-loop can be considered as endlessly running single-threaded loop which doesn’t know how to stop.
Then how does the NodeJs Framework work all together ???
So whenever we want to run a new chunk of code, it goes to stack for execution, but here is the twist which brings this whole non-blocking I/O model concept into the ground.
If a block of code that is going to be executed is an AJAX request, DOM operation or any other timeout function, then it is going to take time and NodeJs is an asynchronous programming language so it’s not going to wait for the response of the AJAX call or for that matter the timeout function to get over completely, instead what it will do is, the respective chunk of code will move to callback queue which works on FIFO.
Meanwhile, the event-loop which has only one job to do is to check whether the stack is empty or executing any other block of code. The moment event loop finds stack empty it moves the very first item queued in the callback queue to the stack and the process keeps repeating.
And this is how NodeJs manages to be a non-blocking I/O system and single threaded at the same time which eventually makes it a very powerful, lightweight and efficient model.
- NodeJs uses the libuv library to handle all the async operations. libuv (Unicorn Velociraptor Library) is a multi-platform C library which provides support for asynchronous I/O events for windows and POSIX based system such as MACos, Linux and UNIX.
NodeJs based web frameworks :
Here I am listing out some of the best NodeJs frameworks which can be used to build web applications.
- Express.js: Well who doesn’t know express.js, we can assume it as a mid layer built upon the NodeJS framework which manages the server, routes and provides a robust and very powerful set of features to develop web applications. It can be used to design single-page, multi-page and hybrid web applications. It also allows to setup middlewares to respond to HTTP Requests.
- Loopback.io: I myself have worked on loopback.io to create a complete product, it will let you create a humongous number of APIs with the very little amount or no coding. It is designed to enable developers to easily set up models and create REST APIs in a matter of minutes and once you define a model that is the data structure then loopback will work for you and create almost all the conventional CRUD APIs. With its huge library and great documentation using which you can create a complete web application within a short span of time.
- Hapi.js: Hapi.js (also known as Hapi) is an open-source framework for web applications. The most common use of Hapi is to build web services such as JSON API. You can build an application programming interface (API) servers, websites, and HTTP proxy applications with hapi.js.Hapi provides a robust plugin system that allows you to add new features and fix bugs at a fast pace. It has an enormous number of plugins available for almost what you need.
- Mojito: Mojito was developed for the agile development of web applications. The Mojito framework offers an extensive API with modules for executing code, making REST calls, handling cookies and assets, accessing parameters and configuration, and more. The framework can detect the type of calling devices and serve the appropriate HTML markup.
- Keystone.js: KeystoneJS is an Open Source, NodeJS based CMS(Content Management System) and Web Application Platform. Here in Keystone.js, the database is MongoDB — a NO-SQL Document store database, and the Node framework and ExpressJS work behind the scene. Here CMS is typically a web-based application which let you create, modify and control the digital content.
- Adonis.js: AdonisJs is a Node.js MVC framework that supports almost all operating systems. It offers a very compatible and solid eco-system to write a server-side web application so that you can focus on what market and implement different business logic. It has a very sturdy ORM to make SQL queries and also provides API and session-based authentication system.
- Koa.js: Koa is created by another NodeJs Web framework developer from Express.js. The special features of Koa are its error handling capabilities, cascading middleware, generators, and HTTP methods.
Release and Maintenance NodeJS:
Every new release of NodeJs is detached from its GITHUB master branch every six months. All the Even-numbered version is cut in April and every odd-numbered version in October.
Also whenever a new odd version is released the previous even-numbered version undergoes a transition to Long term support (LTS) which gives it 18 months active support from the day it is designated to LTS.
Latest release and features for NodeJs Framework:
The very latest version of NodeJs release with long term support is version 10.x where the code name is Dubnium and was released on 24th April 2018 along with following features.
Added error codes: This is one of the major releases as error handling has always been a pain in NodeJs as for errors used to be a string message. So the only way to take any action for a particular error was a string comparison and any update in strings will ultimately require the code changes.
Performance improvement with v8 engine v6.6: V8 team claims that there is a reduction of 20% to 40% in both the compilation and parse time which provides the end user a great experience while working with applications built on NodeJs.
Support for ES modules: NodeJS hasn’t provided the full support for es modules in the v-10x release but they are working on building NodeJs own ESM spec. NodeJs Framework has been using commonJS module for modular programming which requires module.exports and requires syntax. After the release of the new ECMA SCRIPT MODULE system which uses import and export syntax, Node is also progressively working to deliver its own solution. To know more about ES modules, please go through this article.
And boom !!! you have learned so many things. There are tons of tutorials and resources available to learn NodeJS which you can use to learn many more new concepts of NodeJs and build great things !!!
If you like what we are doing, Like and Share.