Calling a node.js script from inside java


How can I call a node.js inside java and save the console.log values in a String variable?

4/21/2016 9:34:00 AM

Accepted Answer

It is possible for a Java application to communicate with a running Node.JS application. For instance, you can have a Node.JS app running on an available port and the Java app can communicate with it via tcp sockets.

Or you can create an http server and expose a rest service which your Java app can consume.

Or as md_5 says, you can use Runtime.exec and then call getInputStream on the resulting process.

The ways you can communicate between node.js and Java are no different from other cross application communication that can be done.

It is also possible to invoke Java code from your Node.JS application using something like node-java.

11/26/2013 12:00:40 AM

Check these projects which allow you to run node.js scripts inside the jvm

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow