title: Call java program from Node.js application
body: <p>From what I read, there are a couple of ways to run <code>java</code> files in a <code>node.js</code> application. One way is to spawn a child process: (the java code is packaged with dependencies in an executable <code>jar</code>.)</p>
  
  <pre><code>var exec = require('child_process').exec, child;    
  child = exec('java -jar file.jar arg1 arg2',
        function (error, stdout, stderr){
          console.log('stdout: ' + stdout);
          console.log('stderr: ' + stderr);
          if(error !== null){
            console.log('exec error: ' + error);
          }
      });
  </code></pre>
  
  <p>The other way is to use the <code>java - npm</code> module (<a href="https://www.npmjs.com/package/java" rel="noreferrer">link</a>), a wrapper over <code>JNI</code> (this will let me create <code>objects</code>, set and get <code>attributes</code>, run <code>methods</code>).</p>
  
  <p>In a production environment, when I want my <code>node.js</code> (<code>Express</code>) server to call a <code>java</code> program (it just saves an image to the local directory), please advise me on which would be the better way to accomplish this (in terms of best practices). Also, there is a long list of <code>arguments</code> that I need to pass to the <code>main</code> class and doing that on the command line is a bit of a struggle. Should I make the <code>java</code> program read from an input file instead?</p>