Run Java server program from Node.js / Heroku application?

Can I call a Java program from a Node.js application on Heroku?

I have a Node.js / Heroku application. But now you need to add the server ability to run the algorithm on the input data file and output the data in JSON format. I already have a Java library that can read the file and run the algorithm, and it would be very difficult (at best) to rewrite it in its pure form Node.js.

So, you can write a command-line program that takes an input file and passes the results to stdout, for example.

java mytask.class -cp ./mylibrary.jar --in /tmp/file.in > output.json

Is it possible to output a call to the Java command line program from Node.js? I know that you can deploy Java applications to Heroku, but here you need to run a bit of Java from the Node.js. application.

+4
source share
1 answer

Don't want this and child_process.exec() in particular?

Node provides three-way penetration (3) through child_process.

You can transfer data through the child stdin, stdout and stderr completely without blocking.

Please note that the above command of your example is incorrect, as you are trying to connect to a file ( output.json ). Pipes only work between processes. The child process module will allow you to directly read the stdout of the processes and you will not need a file (similarly for the input stream)

+3
source

All Articles