Language: EN

que-es-node-js

What is Node.js and why you should already be using it

Node.js is a tool that has become undeniably popular in recent times, to the point of becoming an indispensable component in the development of web applications.

We do not intend to make a detailed analysis of the features, but rather a simple description of its main characteristics, the reasons for its success, and why, if you have not already done so, you should include it as a standard tool in your repertoire.

But, before we go into depth, note that Node.js is Open Source, it has an extensive community of users and collaborators, and it is available through its website at https://nodejs.org/

What is Node.js?

Interestingly, it is quite difficult to explain what Node.js is in a brief way. It is not as simple as saying “a web server” or “a development environment” (and it is neither of those, and a bit of both) or is a… “whatever it is”.

And it is that, as often happens with really good tools, Node.js serves many purposes. Let’s see the definition given in Wikipedia:

Node.js is a multi-platform, open-source, runtime environment for the server layer (but not limited to it) based on the ECMAScript programming language, asynchronous, with data I/O in an event-driven architecture and based on Google’s V8 engine.

That didn’t improve things much, did it? Well, let’s try to fix it and see a summary of some of the characteristics of Node.js that have contributed to its current success.

JavaScript on the server side

It is well known that when communicating between two devices (computers, mobile, tablet, IoT) there is often a machine that acts as a server, and one or more clients.

Clients communicate with the server, and it returns information to them, which can be anything from a web page, data stored in a database, a message transmitted by another client… anything.

Traditionally there are languages that run on the server (PHP, ASP, JSP, Ruby…) and others that run on the client (in the Web, mainly JavaScript).

Precisely one of the first features that catches the eye of Node.js is that it “flips” this situation, running Java Script on the server side.

javascript-logo

It is not the only server-side technology that works with JavaScript (nor was it even the first) but it is certainly a characteristic of Node.js.

One of the reasons for choosing JavaScript is that it is a widely used language and intimately related to web development. For this reason, the learning curve is simple for a large number of developers.

On the other hand, the asynchronous and event-driven design features of JavaScript made it suitable for the main purpose of Node.js, which we will see right away.

Focused on scalability

Node.js was designed with scalability in mind, particularly with the ability to support a large number of simultaneous connections to a server.

Many server-side technologies execute the environment of each request in an independent thread. When the number of requests increases, the server’s consumed resources also increase.

In addition to the performance constraints of a computer (RAM, CPU, connection speed), the bottleneck on a server is often the input and output (I/O) processes.

As an alternative, Node.js uses a single thread and an asynchronous event loop. New requests are treated as events in this loop. This is why the asynchronous features and events of JavaScript fit so well into the philosophy of Node.js.

This allows Node.js to efficiently handle multiple connections and requests, making it suitable for development and applications with a large number of simultaneous connections.

nodejs-scalability

Examples include the development of APIs, web applications with Ajax / Websockets requests, push messaging applications (RabbitMQ, ZeroMQ). Of course, it also plays a prominent role in the “Internet of Things” (IoT).

On the other hand, in general, Node.js is not suitable for applications that require a small number of connections with high resource consumption (calculation applications, intensive data access, etc).

NPM Node Package Manager

Undoubtedly, another reason for the success of NodeJS is its package manager NPM (Node Package Manager). This allows us to access a huge number of open-source libraries developed by the community (and I emphasize, HUGE).

npm-logo

Among the thousands of packages that exist, we have notable ones such as Express, React, Gulp, Socket.Io, Jade, Mongoose, Browserify, Forever, among many others. It is an entire ecosystem that you should know!

The complete list of available packages is at https://npmjs.org/.

A standard in web development

Is that all? Well, no! Although Node.js is neither a web server nor a development environment, the enormous community and the huge library of available open-source packages have made it one of the standard tools in web development.

nodejs-development

Frequently, web developers use Node.js, and the many available tools, to develop web applications quickly. Running tasks, transcompiling, minifying resources, real-time browser synchronization… are just some of the options we have readily available in Node.js and that save a huge amount of time.

Subsequently, this development can be deployed in the production environment, either using Node.js itself, a web server like Apache or Tomcat, or even embedding it in an IoT device.

Conclusion

Node.js is one of the trend-setting tools for years. If you are truly interested in applications that communicate over the Internet (including web development and IoT) you should already have it installed.

Its features make it interesting in itself, but, combined with the enormous amount of tools and the large existing community, it makes it essential to know how it works.