title: Check if package installed from within Node.js script
body: <p>I'm trying out Node.js for scripting. </p>
  
  <p>I have a script, where I check the existence of <code>./node_modules/some-package</code>. If it doesn't exist, <code>some-package</code> is installed.</p>
  
  <p>This seems kind of hacky however.</p>
  
  <p>Is there a better way to check if a particular package is installed from within the script?</p>
  
  <h3>sample code</h3>
  
  <pre><code>const fs = require('fs');
  let installed;
  
  try {
    fs.accessSync('./node_modules/.bin/some-package');
    installed = true;
  } catch (err) {
    installed = false;
  }
  </code></pre>