title: Read npm config values from within a Node.js script
body: <p>Within Node.js, I would like to read the value of the <code>registry</code> property that npm uses to determine where to download packages.</p>
  <pre class="lang-js prettyprint-override"><code>const registry = someApi.get('registry');
  </code></pre>
  <p>I want to know so that I can create a <a href="https://docs.npmjs.com/misc/scripts" rel="nofollow noreferrer">preinstall</a> script that ensures developers are downloading packages through the local <a href="https://www.jfrog.com/confluence/display/RTF/Npm+Registry" rel="nofollow noreferrer">Artifactory</a> instance rather than directly from npm.org.</p>
  <pre class="lang-js prettyprint-override"><code>const EXPECTED_REGISTRY = 'https://example.com/artifactory'
  const registry = someApi.get('registry'); 
  if (registry !== EXPECTED_REGISTRY) {
     console.log('Please configure your .npmrc to use Artifactory');
     console.log('See http://example.com/instructions');
     process.exit(1);
  }
  </code></pre>
  <p>One way to do it would be to shell out to <code>npm config list --json</code>. There must be an API that will give me the same result. I'm just having trouble finding it.</p>