B. TIger B. TIger - 6 months ago 55
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?


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");


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