Is Node.js a Number-one Hit for Creating Web Applications?
- Nov 25, 2020
- 3 min read
Updated: Dec 5, 2020
If you've just started to consider switching to Node.js, but you have no idea whether it's the right choice, this article is for you!

Javascript is one of the most popular and commonly-used languages in the world. Arguably it's the most frequently chosen language among beginners, and it has tons of intriguing libraries to pick. If you know this language, you know what I'm talking about - it's intuitive, easy to use and it allows you to work with JSON data format effortlessly.
Now, imagine, what if you could take the same language and create complex web applications with it?
After a very long time having to deal with stateless request-response paradigms, we finally get a technology that allows the client and server to communicate and exchange data freely.
Introduction
Node.js is an open-source server environment which allows you to create real-time websites with push capabilities. Primarily, Ryan Dahl - the creator of Node.js was inspired by applications such as Gmail. What's so cutting-edge about this technology? After a very long time having to deal with stateless request-response paradigms, we finally get a technology that allows the client and server to communicate and exchange data freely. That makes it a perfect tool to create streaming applications such as Netflix, chat applications and social media platforms.
Even though Node.js has many advantages, there are some exceptions in which you would avoid using it. Plus, developers have to be careful when developing with this technology, for it comes with some disadvantages that in some cases are too big to ignore.
Node.js explained
Node.js differs from such languages as PHP in many ways. First of all, unlike PHP, it uses a model that is focused on achieving event-driven and non-blocking I/O, which is primarily single-threaded. That is the reason why, for some people, Node.js is a challenging technology to learn. Don't get me wrong, this technology allows developers to build robust applications with thousands of concurrent connections. But as you can probably imagine, there is a problem with sharing one thread in such big applications. For many people, this is a huge obstacle to overcome when working with Node.js. Developers need to be exceptionally cautious not to block the thread. Furthermore, any heavy computations could easily block it and crash the application. Every incoming request would be blocked with the thread being occupied with one heavy task. That is why Node.js might not be the best solution in some cases.
To avoid continuously blocking the thread, you need to make your code as asynchronous as it's humanly possible. The event-driven nature of this technology and the frequent callbacks you'll encounter in Node would make it very difficult to create anything - if not promises. If you haven't got familiar with the concept of promises yet, then do so, because in Node.js you'll be using them more often than you'd think.
Event-driven programming is a paradigm that determines the control flow of a program by the events that are occurring in it. If you are familiar with Javascript then you probably know event listeners and event handlers. The same principle applies to an application created in Node.js. Your server waits for a request, and only when the request comes to the server, it then produces a response. Pretty self-explanatory, huh? 😄
Here's an example of a simple server object that is created virtually in every Node application at some point. The function that is passed into the createServer is called every time someone makes a request to the server. Once the request is made, you can then determine what the response will be. The object which is returned by createServer is named EventEmitter. That, in simple words, is what event-driven programming means.
const http = require('http');
const server = http.createServer((request, response) => {// magic happens here!});When to use it?
While Node might not be so smart choice when dealing with some CPU intense processes, it seems to be a perfect solution for streaming platforms or chats. As a matter of fact, chats are amazingly easy to build with Node.js, and they are often practice-projects for people who are just starting with this technology. If you'd like to practice and create a chat application yourself, it can be easily done with Socket.io. Go to the official website and see how you can do it with this tool, writing no more than thirty lines of code.
Conclusion
Node.js is a perfect technology for creating large scale applications, social media platforms, streaming services, chats and everything you can imagine that isn't so CPU intensive. However, you need to understand how it works behind the scenes so that you can avoid continuously blocking the thread. Many developers who are extremely good at coding with Node, still run into those kinds of issues. That might be easily the biggest pitfall of this technology. Nonetheless, if you're still interested in learning it, wait for other upcoming articles about Node.js in the future.




Comments