How to implement worker threads in Node.js

Click for: original source

An article by Ganeshmani P about implementation of worker threads in Node.js. After the release of Node.js V10.5.0, Worker Threads are available in the Node.js module.

Javascript is a single threaded programming language. The single thread is one thread which does all the operations of your code. JavaScript engine will run as a single thread and all the operating system IO will happen in parallel. When it returns the results to JavaScript code, it will be operated in a single thread.

Under some circumstances a single thread doesn’t perform well. One of them is CPU Intensive Task. CPU Intensive tasks are the one that blocks the main thread.

The article then discusses solutions:

  • Child process
  • Worker threads

You will get example of implementation of both with explanation of advantages and disadvantages. The JavaScript code provided in the article. Nice!

[Read More]

Tags nodejs javascript web-development programming