title: How to detect and automatically install related dependent modules before starting a Node.js application?
body: <p>I want my <code>Node.js</code> application to automatically install and run the relevant dependency modules before starting.</p>
  <p>So I wrote <code>package.json</code> like this:</p>
  <pre><code>{
    &quot;name&quot; : &quot;cli&quot;,
    &quot;version&quot; : &quot;1.0.0&quot;,
    &quot;description&quot; : &quot;&quot;,
    &quot;main&quot; : &quot;./app.js&quot;,
    &quot;scripts&quot;: {
      &quot;start&quot; : &quot;npm install &amp;&amp; npm start ./app.js&quot;,
      &quot;test&quot;  : &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
    },
    ...
  }
  </code></pre>
  <p>However, the above <code>package.json</code> is unconditionally reinstalling the module and running. I tried adding <code>install</code> to <code>&quot;script&quot;</code>, but I get an error saying that the module doesn't exist.</p>
  <p>How can I write <code>package.json</code> to check if a module is installed, and if not, install and run it?</p>
  <p>Or could writing a batch file be the way?</p>