15-11-2022
Node.JS: the potential of the platform that made JavaScript grow
by Diogo Salaberri, Technical Project Manager @ Xpand IT
To help you and explain what Node.JS is, a little bit of context is needed. First, let us talk about JavaScript! The famous programming language was created by Brendan Eich at the end of 1995.
However, the JavaScript we know today is already different because it used to be in a still new field, the Web, where languages like PHP and Java (JSF – JavaServer Faces) already existed. JavaScript developed quite a lot until today, but it has always been a Client Side option as, as we know, it works in browsers because each client has its own engines for that.
The world of Web development is usually divided (but not in every case) into Backend and Frontend, due to the Client-Server architecture Client-Server architecture and JavaScript. In the case of JavaScript, which already had its space to work Frontend, with a very clear limit ahead: Backend. And this is where our central theme, Node.JS, comes in.
What is Node.JS?
According to the platform’s own website, Node.JS ” is an open-source cross-platform JavaScript execution environment.” Node.JS was not the first attempt to take JavaScript out of browsers. Several options emerged, but ran into issues of performance, usability, etc., and ended up going wrong. What gives Node.JS notoriety is that it succeeded, opening up a new world into which JavaScript could grow.
The environment runs on the implementation of the JavaScript V8 engine, created by Google and present in Chrome and Chromium browsers, and this explains how it was possible to have the languages interpreted outside the browsers. After all, if a JavaScript engine is needed and it’s no longer running (being interpreted) in the browser, an environment that has its own engine is created – that’s Node.JS.
Node.JS – Exploring the concepts…
Now that it’s clear how the Node.JS environment was able to interpret JavaScript outside of browsers, more attention is needed on a few concepts that helped the platform consolidate itself as a viable choice in Server-Side development.
Unlike concurrent languages, Node.JS is single-threaded, which means that there is only one thread to handle requests. This single thread is called the Event Loop and it is very important to also mention that it is non-blocking – a key concept to make this work. A non-blocking thread means that the Event Loop is not blocked and waiting for requests to be resolved. The Event Loop receives requests, passes on the work, and waits for the next request, treating them as asynchronous.
Node.JS is cross-platform, which means that applications written in JavaScript can operate on different platforms such as Windows, macOS and Linux. All it takes is having Node.JS installed to interpret code, no matter where it’s running.
Node.JS comes with an extra …
When Node.JS is installed in the development environment, it also comes with NPM which, due to its importance, is also worth mentioning. This is the Node Package Manager: a JavaScript package manager for Node.JS. This makes the platform even more attractive to the community because it brings several third-party packages to add to its application. In practical terms, it does not require a user to do everything by himself; if someone in the community has already solved the problem, they probably published the solution in NPM, and it can simply be added to an application.
The most common Node.JS applications
- REST API: Node.JS shines when used to develop REST APIs. Putting together a few libraries makes it possible to quickly have a REST API serving or integrating applications. Speaking of REST APIs with Node.JS, JS, a flexible and minimalist web framework, immediately comes to mind. Such a framework can easily be added to a project through NPM;
- Real-time: real-time applications, such as chats, force a high traffic of information, often to several devices. These applications involve the use of the concepts of cross-platform, asynchronous and non-blocking requests
- Proxy API: another very common way of using Node.JS is to create Proxy APIs, which is a layer that is usually above other APIs, routing calls, data or even acting as a Load Balancer.
Conclusion
Node.JS may no longer be new to JavaScript developers, but it is still of great importance in the community, not only for what it has done in the past, but for what it does for JavaScript frameworks through NPM.
To conclude, and since this text is written in 2022, Node.JS is already fully accepted and consolidated as a JavaScript development environment and will always be remembered as a platform that broke the boundaries of Server-Side solutions. In addition, there are already solutions written on top of Node.JS, such as Nest.JS, which bring TypeScript, as well as several abstractions.
Leave a comment
Comments are closed.