Within Node.js, I would like to read the value of the registry property that npm uses to determine where to download packages.
const registry = someApi.get('registry');
I want to know so that I can create a preinstall script that ensures developers are downloading packages through the local Artifactory instance rather than directly from npm.org.
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);
}
One way to do it would be to shell out to npm config list --json. There must be an API that will give me the same result. I'm just having trouble finding it.