Node.js? What’s that?

Node.js

What’s the deal with Node.js right? As you know, JavaScript used to be a language that only worked on the client-side. And then Chrome V8 Engine, which we run in the browser, has been made available to us and now we can use JavaScript on the server-side as well. Basically, Chrome V8 Engine, which allows us to use the Javascript language on the server-side, is called Node.js.

Node.js is basically server-side javascript. Since it is based on Javascript, it has a very dynamic and fast structure.

By moving Javascript language to the Back-end via Node.js, you can now develop a full-stack application knowing only one language. Recently, Javascript Front-End libraries and frameworks such as React have become very popular.

So why has Javascript and Node.js become so popular lately?

The most important feature of Node.js is that it works asynchronously and is non-blocking. So what is this asynchronous operation and non-blocking?

I think you will understand the logic of asynchronous and non-blocking work very well with an example of a restaurant. Imagine you go to a restaurant and order. You will give the order to the waiter, he will inform the cook and the cook will start cooking for you. Let’s say that the cooking time of the dish you want is 30 minutes. By the way, of course, you’re not the only one in the restaurant. Many people will order at the same time and the cooks will start preparing the dishes. If the waiter didn’t take other people’s orders until your food is made and delivered to you, other customers waiting to order after you would have wasted a lot of time. But the waiter took the order and forwarded it to the cook and then took someone else’s order, forwarded that too. So none of the customers waited to order and wasted time. In this system, one person’s request did not prevent another’s work.

The same system exists in the Node.js working logic. When a request is sent to Node.js for processing, Node.js receives it and processes it immediately, but does not wait for this process to finish to receive the other requests. It takes requests in turn and continues without waiting for results. Posting responses as they come. It works in the same restaurant logic, and in this case, a request does not block the other requests because it does not wait for the other request to finish. Whichever ends first, the response to that request comes. This logic is called asynchronous operation and it is non-blocking because one operation does not prevent another operation.

The example above illustrates the difference between asynchronous and synchronous operations nicely. In synchronous transactions, a total of 4 transactions took 45 seconds to complete, as one transaction was waiting for other transactions. But in the asynchronous structure, it took 20 seconds because it was not dependent on the end of the other operation. Here, Node.js gains serious speed with this asynchronous structure. At the same time, it offers a solution to the scalability problem as it can respond quickly to multiple users. This is actually one of the main reasons for its popularity. If we are developing a system that thousands of people use at the same time, Node.js will be a very good choice.

One of the biggest advantages of Node.js is its modular structure and the package management system that supports this structure, npm (Node.js package manager). We can think of npm as a repository containing many modules to be used in Node.js projects. These modules are written by open-source developers and installed on npmjs.com. Currently, more than 1 million packages and modules have been added in npm. This actually shows its popularity really well.

I think that’s pretty much about it. Thanks for reading!

Cheers!