B. TIger B. TIger - 1 month ago 13
Java Question

Can I execute a node.js script from a Java Class?

I am currently developing a Java system that communicates with node.js using socket.io. The system and the script are on the same server. How can I execute the script from my Java code and keep it alive from my app?

Answer

Say you have a node.js script named "mynodejs.js". You can use the following java code:

Process p = Runtime.getRuntime().exec("node mynodejs.js");

or

ProcessBuilder b = new ProcessBuilder("node mynodejs.js", "-args");