title: How to run a command line tool from node.js application
body: <p>The title of my question is how to run a command line tool from a node.js application because I think an answer here will apply to all command line utilities installable from npm. I have seen questions related to running command line from node.js, but they don't seem to be working for my situation. Specifically I am trying to run a node command line utility similar to npm (in how it is used, but not its function) called tilemantle.</p>
  <p>tilemantle's <a href="https://github.com/naturalatlas/tilemantle" rel="nofollow noreferrer">documentation</a> shows installing tilemantle globally and running the program from the command line.</p>
  <p>What I would like to do is install tilemantle locally as a part of a npm project using <code>npm install tilemantle --save</code> and then run tilemantle from inside my project.</p>
  <p>I've tried `tilemantle = require('tilemantle'), but the index.js file in the tilemantle project is empty, so I think this won't help with anything.</p>
  <p>I tried the project <code>node-cmd</code></p>
  <pre><code>const cmd = require('node-cmd');
  cmd.run('./node_modules/tilemantle/bin/tilemantle', 'http://localhost:5000/layer/{z}/{x}/{y}/tile.png', '-z 0-11', '--delay=100ms', '--point=37.819895,-122.478674', '--buffer=100mi'
  </code></pre>
  <p>This doesn't throw any errors, but it also just doesn't work.</p>
  <p>I also tried child processes</p>
  <pre><code>const child_process = require('child_process');
  child_process.exec('./node_modules/tilemantle/bin/tilemantle', 'http://localhost:5000/layer/{z}/{x}/{y}/tile.png, -z 0-11 --delay=100ms --point=37.819895,-122.478674 --buffer=100mi'
  </code></pre>
  <p>This also doesn't throw any errors, but it also doesn't work.</p>
  <p>Is there a way to get this working, so that I can run tilemantle from inside my program and not need to install it globally?</p>
  <h1>Update</h1>
  <p>I can get tilemantle to run from my terminal with</p>
  <pre><code>node './node_modules/tilemantle/bin/tilemantle', 'http://localhost:5000/layer/{z}/{x}/{y}/tile.png', '--delay=100ms', '--point=37.819895,-122.478674', '--buffer=100mi', '-z 0-11'
  </code></pre>
  <p>If I run the following as suggested by <a href="https://stackoverflow.com/a/45890302/4708150">jkwok</a></p>
  <pre><code>child_process.spawn('tilemantle', ['http://myhost.com/{z}/{x}/{y}.png',
    '--point=44.523333,-109.057222', '--buffer=12mi', '-z', '10-14'],
    { stdio: 'inherit' });
  </code></pre>
  <p>I am getting <code>spawn tilemantle ENOENT</code> and if I replace tilemantle with <code>./node_modules/tilemantle/bin/tilemantle.js</code> I get <code>spawn UNKNOWN</code></p>
  <p>Based on <a href="https://stackoverflow.com/a/45889764/4708150">jfriend00's answer</a> it sounds like I need to actually be spawning node, so I tried the following</p>
  <pre><code>child_process.spawn('node', ['./node_modules/tilemantle/bin/tilemantle.js', 'http://myhost.com/{z}/{x}/{y}.png', '--point=44.523333,-109.057222', '--buffer=12mi', '-z', '10-14'], { stdio: 'inherit' });
  </code></pre>
  <p>Which gives me the error <code>spawn node ENOENT</code> which seems strange since I can run it from my terminal and I checked my path variable and <code>C:\Program Files\nodejs</code> is on my path.</p>
  <p>Just to check I tried running the following with a full path to node.</p>
  <pre><code>child_process.spawn('c:/program files/nodejs/node.exe', ['./node_modules/tilemantle/bin/tilemantle.js', 'http://myhost.com/{z}/{x}/{y}.png', '--point=44.523333,-109.057222', '--buffer=12mi', '-z', '10-14'], { stdio: 'inherit' });
  </code></pre>
  <p>which runs without the ENOENT error, but again it is failing silently and is just not warming up my tile server.</p>
  <p>I am running Windows 10 x64 with Node 6.11.0</p>