Re: Why is Node.js Single-threaded?
Hello Hie,
that is a general Node.js question, and I suggest you to ask it using more appropriate channels like Stack Overflow.
This forum is for questions specifically related to the MySQL X DevAPI connector for Node.js.
In it's most basic concept, Node.js is single threaded because it uses an event loop to handle asynchronous work, in particular blocking IO tasks, which ensures the main thread is never blocked on a given process.
There are multiple resources online that describe how the event loop works in the scope of JavaScript). I would personally recommend the following video to get a better grasp.
https://www.youtube.com/watch?v=8aGhZQkoFbQ
Nowadays, Node.js actually supports using threads within a process:
https://nodejs.org/dist/latest/docs/api/worker_threads.html
These threads (also known as workers) are more useful for performing CPU-intensive operations in JavaScript.
Hope it helps.
Thanks
Rui
Subject
Written By
Posted
Re: Why is Node.js Single-threaded?
January 10, 2023 10:05AM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.