Answer the question
In order to leave comments, you need to log in
What are threads in node.js?
Guys explain in an accessible way what are streams in node.js and what are the advantages of using them?
Answer the question
In order to leave comments, you need to log in
This is such a thing that gives out (or receives, or both) data in chunks (chunk). To explain why they are needed, we need to digress a bit and remember how nodejs works.
The advantage of nodejs is that while the database or file system is responding to the command, we can start another callback. Due to this, we can process many requests in parallel, but from the point of view of the programmer, there is no parallelism, there are no threads, the race condition does not arise, and his head does not hurt about it. And everything works fast for us, as long as no function takes the processor for too long, as long as it does not work for too long. And if it takes, then, due to single-threading, all our other requests will hang.
But sometimes we still do a lot of work - read or write a large file, for example. With the help of threads, we split this work into pieces that do not take a percentage for a long time. This is not always possible, but in a large number of cases it works for itself.
PS This answer is about stream (not to be confused with thread).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question