How to integrate Java with nodejs for handling CPU-heavy tasks?

As mentioned in a previous answer, you can use node-java which is an npm module that talks to Java. You can also use J2V8 which wraps Node.js as a Java library and provides a Node.js API in Java.


The answer is lambda architecture.

NodeJs is nice by itself - handling fast queries in a lightweight manner, not doing any extra computations on data.

The CPU heavy tasks can be easily delegated to specialized components based on JVM (well, the most famous ones are on JVM). This is nicely implemented by using message brokers and microservices.

An event-based architecture, where nodejs can be hooked up to databases like Cassandra or Mongodb and cluster computing frameworks like Apache Spark (not necessarily, though, it depends on the problem) to handle the cpu-heavy parts of the system. And lightweight containers add an icing to the cake by providing nice isolated runtime environments for each of the components to live in.

That's my conclusion so far regarding this question. I think the suggestions above sort of eliminate the need to wrap node under java or other JVM based solution for cpu-heavy tasks.


You can intergrate NodeJS with Java using node-java.