I read on node.js's official site that Node.js is a JavaScript run time built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O mode and highly scalable for network applications. And some thread I read that it is not for CPU intensive tasks. Is that mean that its not a good idea to use node.js for solving problems like TSP, exact cover or graph coloring?


The default event model for Node.JS is single-threaded, cooperative multitasking. If you are I/O bound, Node.JS can simply accept new requests while yours is waiting for the database call to complete. But if you are CPU bound, you chew up clock cycles while other requests have to wait.

There are, of course, ways to get around this. One way is to spin up new threads to handle your long-running computations, just like you would in any other application. This drops the multitasking load onto the operating system, which has better facilities for multitasking. Because it's all Javascript, you can run some of it on the server and some of it in the browser.

There are some intricacies, of course. You can find out in detail what they are and how they work in the article I link below.

Further Reading
Why you should use Node.JS for CPU-Intensive Tasks.

| improve this answer | |

You can use node.js for calculating whatever you want, even TSP problems or graph coloring. For example, I implemented a lot of Project Euler problems in node.js just for the purpose of learning Javascript, and I was astonished about the speed, which is is comparable to other JIT compiled language implementations, much better than the experiences I had with other scripting languages like Python or Perl.

However, if node.js is a "good-enough" choice for your use case, or if there are better alternatives is a completely different question. This depends a lot on non-functional factors like if you want to run your program as part of a web service, the number of concurrent computations you need to process, the need for multithreading, the requirement of reusing existing libraries, and so on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.