In 2009, the Node.js platform made its modest first steps in the endless world of backend development. It was the first attempt to use JavaScript in server applications. Today it will be extremely difficult to find a web developer who has not heard of Node. But it cannot be said that the existence of the Node was cloudless. This platform has experienced a split in the community, has been the subject of wars of forum and has driven many to despair.

Perhaps you think that such statements sound too pompous. However, try searching on Google and you will encounter an inexhaustible source of
endless debate . Among the arguments not in favor of the Node that you may encounter, there are, for example, those who, asking about what happened to the axiom about using the best available tools for solving a certain task, indicate that JS did not stand next to the correct server toolkit.
Other criticisms of JS, such as “Callback hell is real”, calling for believing in the reality of hell callbacks sound like lines from a poem.
Some of the critics of Node express more directly and unambiguously: “Node is a cancerous tumor”.
I suppose it is time to restore the true state of things, to dot the i's in terms of the Node.js platform and JavaScript as a language for server development. Today we will talk about the current state and development of Node.js, the most successful options for using this platform, its limitations, and the technologies created on its basis.
The current state of Node.js as a server platform
Before we talk about how
Node server platform looks like today, let's remember what it is.
')
Namely, this is a JavaScript runtime built on the basis
of the V8 JS engine developed by Google and used in Google Chrome. Node.js uses a non-blocking, event-driven I / O model that makes this platform simple and efficient.
At the beginning of this material, Node is shown as a programmer’s nightmare. However, this platform did not accidentally become very popular. Here we will not rely on allegations. Better take a look at the facts. Namely, a fresh
study of Stack Overflow shows that Node.js is, by far, the most popular technology among developers.
In addition, JS is a language whose popularity is growing faster in the last five years than in other languages, despite the fact that C # and PHP are losing ground. The prevalence of JavaScript, if not even talking exclusively about Node, goes up.
How can one explain that JavaScript, as a server language, was so quickly and widely accepted by the developer community? Simply put, Node experienced a stage in which it was perceived as a kind of fun, and entered the phase of stability and maturity. A powerful community has formed around it, the size of which is steadily growing. The Node Ecosystem is also worthy of mention, since, for example, the Node package manager,
npm , is currently represented by the largest registry of software on the Internet.
Node.js not only made a revolution in server development, but thanks to it, a contribution was made to the performance of client applications, since serious forces were involved in the development of the V8. In addition, it plays a prominent role in extending the entire JavaScript ecosystem and in improving modern JS frameworks such as
Angular ,
React, or
Vue .
Over time, Node was able to refute the prejudices of the early days. Here are some of them.
JavaScript code for Node.js is notorious for debugging complexity.
To debug server JS applications, you can use the same techniques that are used to debug client code, using
node-inspector , where the tools of the Chrome developer tools are collected.
Then, for example, Joyent developers, who understand something about debugging and profiling Node applications, have already released the universal
DTrace debugger long ago.
Node cannot be used to develop enterprise-class server applications.
This statement is also not true. On the basis of Node, you can create corporate systems. The difficulty lies only in the fact that it does not have a lot of built-in tools that simplify the creation of such systems. However, notable players in the IT market use Node as a corporate web platform. Among them - Netflix. PayPal, Yahoo !, Walmart.
JavaScript is a dynamic language, therefore, while working on it, you cannot use something like static type checking during compilation.
It's true. However, tools like TypeScript and Flow appeared in the JS ecosystem, which are aimed at working with types in JS, which allows to increase the stability and predictability of programs, simplify debugging. In this area, you can use the capabilities of
Closure Compiler from Google.
JavaScript was not created as a language for server development.
Here you can only say that JS
could already work on servers , at the same time, when Netscape built support for this language into its browser. And it was already in 1995. JS is usually called client-side web development language only because it has completely captured this area.
In fact, the list goes on and on.
Now let's talk about the scenarios for using Node.js and its limitations in order to better understand the place of this technology in the modern world.
Node Application Scenarios
So why bother to consider Node.js as a server development tool in your technology stack?
Advantages and general characteristics
Let me briefly highlight the most important:
- It is very likely that the client parts of your web applications are written in JavaScript. In this case, the universality of the code in the applied technology stack is an important plus of using JS on the server that is worth remembering.
- Tools like webpack help reuse code on both the client and the server, which leads to its uniformity at all levels of the system.
- Using JS on the client and on the server , you can create web applications that can be rendered in the browser and on the server . However, such systems usually work very clearly and clearly. I guess it's just awesome.
- The appearance of the async / await construction in Node has completely changed the approach to writing asynchronous code. Now this code resembles the usual synchronous code, both in appearance and in behavior. The async / await mechanism has been supported in Node since version 7.6 . He, in particular, is the solution to the infamous problem of callback hell .
Some see the convergence of the client and server codebases minus Node.js, saying that it forces the developer to use JavaScript. However, this is not quite true. If necessary, third-party specialized libraries can be accessed from the Node applications.
Let's say you need video encoding tools. In order to equip your project written in JavaScript, you do not have to look for some rare mystery libraries for Node. You can fully use the proven tools, adjusting interaction with them from Node. Or, for example, if there is a certain library in Python that performs the complex calculations you need, you can run microservice especially for working with it and access the corresponding functions of this library through the REST API.
Considering all the above, the following options for using Node.js can be highlighted, in which he fully reveals his strengths.
â–ŤScenario number 1. Real-time applications
Collaboration applications (such as Trello and Google Docs), interactive chats, instant messaging systems, and online games are examples of real-time applications that, when developed, can provide you with particular features of Node.js architecture.
The time required for these applications to perform certain actions can be described, from the user's point of view,
with the words "immediately" and "now .
" For normal operation of such applications, the system on which they are based must provide a very high response rate to user actions and a low level of delays. Node meets these requirements.
Node facilitates the processing of multiple requests from clients, its architecture facilitates the efficient use of libraries, it provides a very fast synchronization of data between the client and the server.
â–ŤScenario number 2. Single Page Applications
A one-page application is an application that is represented by the only webpage that is loaded into the browser, the content of which is dynamically updated as the user interacts with it. Most of the workload during the operation of such applications falls on the client part of the system, written in JavaScript.
Even though one-page applications are a significant step in the evolution of web development, they also have problems that, for example, relate to rendering. In particular, this can adversely affect
search engine optimization pages. A popular solution to these problems is server-side rendering with Node.js.
â–ŤScenario number 3. Scalability
The server on Node will never be much more powerful than necessary. The beauty of Node's architecture lies in its minimalism, in that the server part of the applications can be scaled depending on the needs of the project. The secret here lies in the right attitude to performance.
Even the name of the subject of our conversation, “node”
focuses attention on the possibility of building systems from a variety of small distributed computing nodes that can exchange data with each other.
The modularity of Node allows you to create small applications without encountering the need to support a huge infrastructure, many parts of which in some particular case will be unused. When developing Node-applications, the programmer chooses exactly what he needs, and, if necessary, expands the solution.
However, it should be noted that certain scaling possibilities are associated with certain difficulties. And, if you lose your guard, Node.js can become ... dangerous.
Limitations of Node.js
To be honest, Node allows the developer, as they say, to "shoot himself in the foot." In this world, you have to pay for everything, including for the wide possibilities for setting up the system and fitting it to your needs. If you work with Node, without having enough experience or regularly letting things run loose, you can face serious problems like losing customers.
In contrast to the more traditional approaches that rigidly regulate certain architectural features of the systems, it is you who create the structure that supports the server part of your application. As a result, many decisions have to be made here, that is, the developer needs to know exactly what exactly he is doing, and what will happen to the project if it needs to be expanded.
In the case of other languages, like Ruby, and the well-known Ruby on Rails framework, for example, there is an idea that presupposes agreements over system configuration. These traditional frameworks literally lead the developer by the hand, showing him the right, safe way to solve common problems.
Node turns everything, so to speak, upside down. The developer is given more freedom, but the path to the implementation of the plan may be full of dangers if wrong decisions are made during the work. Here it will be appropriate to recall the notorious “hell of callbacks”, which suddenly turns out to be completely real.
This does not mean that Node can not create large server applications, but the foregoing should always be remembered.
Even the creator of Node.js,
Ryan Dahl , finally, before moving on to other projects, realized the limitations of the system. He spoke on this very unequivocally:
“
I think Node is not the best system for creating large-scale server projects. I would use GO for this. And, frankly, that is why I leave the work on Node. I once realized that, in fact, this is not the best system for server development at all . ”
The previously mentioned prejudices concerning Node were valid until a certain moment of the not so long life path of Node, and they, to some extent, still are not an empty sound. Node has matured enough and grown up; its weaknesses can be circumvented if necessary and available. And the tools developed by the community allow you to create almost anything on the basis of Node.js.
Popular tools for server development on JS
Not too long ago, if someone thought about creating all parts of their system on JS, the thought of a
MEAN stack (MongoDB, Express, Angular and Node) immediately came to mind.
This toolkit has not lost its relevance even nowadays, however, currently in the JS ecosystem there are much more interesting tools for both client and server development, so you shouldn’t limit yourself to MEAN.
Here are some popular modern server JS frameworks:
- Express.js was and still is the most popular Node.js framework . It is fast, compact, does not impose on the developer of rigid architectural solutions. At the heart of its rapid development is simplicity and clarity. Perhaps he is ideologically closest to the other tools behind the ideas behind Node, following which he is a lightweight modular system.
- Meteor , on the other hand, uses pure JavaScript and Node.js inside a fairly large-scale construction. Meteor itself is a whole ecosystem that can be suitable for developing more complex server applications. However, using Meteor can be complicated if you need something that is not built into the system.
- Sails.js is a real-time MVC framework. It was designed to mimic the MVC pattern on the Ruby on Rails platform, but it also included support for the requirements of modern web applications. It works all thanks to the API, which is driven by data, in the presence of a scalable, service-oriented architecture.
- Koa.js is a framework created by the same team that deals with Express. It is promoted as the “next generation framework for Node.js”. It can be described as a system that is compact, expressive and reliable. Koa.js is suitable for developing web applications and APIs.
Of course, this short list contains not all that is created for server development based on Node. Here are some more interesting projects:
Nest.js ,
Hapi.js ,
Socket.io ,
Mean.js ,
Total.js ,
Derby.js and
Keystone.js .
Results
The goal of this article is not to make some final conclusion about whether the Node.js ecosystem offers the best means for server development. This is not about inciting anyone to use Node. I, besides, am not going to say that Node is far superior to other popular server environments that are developed using Java, C #, C ++, PHP, Python, Go or Ruby.
I suppose the most important thing I wanted to do was to show that between the categorical "yes" and "no", which can be found in many discourses on Node and on JS as a server language, if a vast area can be.
And, like it or not, the interest in Node is constantly growing.
At the end of this material, I would like to say that you should not treat any framework as a magic wand that will magically solve all problems. Node.js is just one of the tools in the colossal web development universe. In some situations, he solves the tasks assigned to him exceptionally well, while in others work with him can turn into a nightmare.
The tasks of each developer include a
careful selection of technologies suitable for the implementation of any new project. At the same time, it is important to take into account all the possibilities and not discard the existing alternatives.
For example, in the company Snipcart, where I work, the .NET architecture is used, about which you can tell a lot of unpleasant things. Why was she chosen? Yes, simply because at a particular moment it turned out to be the
best tool for solving the task set before us.
I hope my story about Node will help you make the right decision when choosing a server platform for your next project.
Dear readers! What do you think about server-side javascript and Node.js? Can you share examples of successful (or unsuccessful) use of Node in real projects?