B. TIger B. TIger - 1 year ago 90
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 Source

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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download