DEV Community

Discussion on: Create a backend in Javascript (part 6): How NodeJS work under the hood?

Collapse
 
ericchapman profile image
Eric The Coder

It's a bit complex:

NodeJS is single thread so can only execute one line of code at the same time. But the execution is so fast that it is not a problem at all. Everything will run very very fast.

But, NodeJS can also do multi-thread for exemple if your API do a query to a database and return data, NodeJS will send that long process to a multi-thread execution to avoid blocking.

So NodeJS send only long process to multi-thread, everything else is executed in the single thread.

That's why NodeJS is a good match for web app that do database query but not that good match for computer intensive task like video manipulation or cryptography.

Collapse
 
madeindra profile image
Made Indra

That means if both APIs have database reading/writing, those two APIs call probably won't block each other, is that right?

Thread Thread
 
ericchapman profile image
Eric The Coder

Exact

Thread Thread
 
madeindra profile image
Made Indra

Thanks for the answer Eric, it's very clear