Node.js is Going Multithread: The Future of JavaSript’s Backend Framework

Photo of Krzysztof Tucholski

Krzysztof Tucholski

Jul 10, 2018 • 3 min read

Ever considered using Node.js for CPU-intensive computing?

If so, you must be aware that it is not the best way to go. This, however, may change in the future as a new face of Node.js is appearing on the horizon.

Node.js, a single-threaded JavaScript runtime, offers a number of advantages. It’s got an outstanding, non-blocking I/O performance. It’s also lightweight and efficient, and it provides unparalleled support for real-time solutions, such as or WebRTC. It comes with the largest ecosystem of packages. It’s perfect for developing microservice architecture. All these features make Node.js a great technology, but there’s one domain where Node.js fails. A single thread is great for handling asynchronous code, but it’s definitely not optimal for CPU-intensive computing. In Node.js, any time-consuming computation will block the event loop, which will, in turn, block the whole application.

The latest news from Node.js community makes us think that this is about to change in the near future. The 10.5.0 release has announced multithreading in Node.js. The feature is still experimental and likely to undergo extensive changes, but it does show the direction in which Node.js is heading.

The newest version introduces a worker module, which exposes workers that represent independent JavaScript execution threads. Workers make it possible to run code on multiple threads as well as to synchronize these by means of message channels. Designed to handle CPU-intensive operations, workers are not meant to handle asynchronous I/O. What’s more, unlike cluster mode or processes, workers can efficiently share memory. If you wish to dive deeper into it, please follow the official documentation.

Why would Node.js, boasting about it being single-threaded, now implement a feature that is quite contrary to its fundamental assumption? My idea is that once multithreading is fully functional, Node.js applications will benefit from both single-threading and multi-threading. In other words, Node.js will remain single-threaded, unless it’s decided otherwise to suit specific business requirements. Finally, Node.js will give room for graphics, complex data processing, and machine learning.

Photo of Krzysztof Tucholski

More posts by this author

Krzysztof Tucholski

We're Netguru!

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency
Let's talk business!

Trusted by:

  • Vector-5
  • Babbel logo
  • Merc logo
  • Ikea logo
  • Volkswagen logo
  • UBS_Home