How to handle CPU-intense tasks with Node.js?

Updated: October 2017

When you read about what Node.js is good at it usually goes like this: "Node.js is great for a WebServer. A main part of almost all web-applications is to create, read, update and delete things in the database. Multi-threaded languages have a large memory overhead with this, since e.g. for 1000 requests they create 1000 threads. Since Node.js is single-threaded and non-blocking, you can achieve higher concurrency with the same resources".

And when you read about what it's bad at it usually goes like this: "Since Node.js is single-threaded, CPU-intensive tasks will block all requests from completing, until the task is completed. Therefore Node.js isn't a good solution for CPU-intense tasks".

So does that mean, when first designing your new web-application you have to choose between a system that loses a lot of memory due to threads or one that can't run CPU-intense tasks?! Of course it doesn't. For one, Node.js isn't the only option out there allowing for high concurreny. You could for example implement a WebServer in Golang or even implement a non-blocking Java server. But also with Node.js you aren't stuck with only simple create / read / update / delete requests. The solution to this problem is a task queue.

There are also related StackOverflow and Quora questions:

Become a better web developer by staying up to date