A
A
Andrey Rudakov2022-01-18 16:41:22
Node.js
Andrey Rudakov, 2022-01-18 16:41:22

NodeJS is single-threaded, how then are large-scale projects built on it?

Good afternoon.
NodeJS is single-threaded, how then are large-scale projects built on it?
It is enough to add the code to the Authorization API:

for (let i = 0; i <= 1000000000; i++) {
      console.log(i);
    }

The example is contrived. But the same thing can happen with a long query to the database to get the user during authorization.
And no user will be able to log in.
And that's it, the whole service is unavailable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2022-01-18
@DEMETRA-WORK

> But the same thing can happen with a long query to the database to get the user during authorization.
Can not. The point is that waiting for a response from the database / network / disk, etc. does not require any action from the node and it can do other things at this time.
As a very simplified example, run it in your browser console setTimeout(() => console.log('готово'), 5000);. After 5 seconds, you will receive the message “done” in the console, but all this time you could use the site without any problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question