Node: Run a Java file and return response

java, node.js

Solution

- Compile you java file

- execute it by node? in this way

let childProcess = require('child_process').spawn(
      'java', ['-jar', 'yureJavaFile.jar']
    );

childProcess.stdout.on('data', function(data) {
    console.log(data);
});

childProcess.stderr.on("data", function (data) {
    console.log(data);
});

Problem

Is it possible to run a Java file from a node application, and get the response of it? For example something as simple as: ``` package com.app; public class App { public static void main(String[] args) { System.out.println('Hello World'); } } ``` And I want to get the response `Hello World`

Original source

Related problems