Find the top dir of a package in node_modules
by looking for the first dir
that contains package.json
file. The search stops when it reaches the dir
node_modules
.
Normally this is just Path.dirname(require.resolve(name + "/package.json"))
, but
new node.js and package.json
ES module export blocks requiring package.json
.
const { findNodeModuleDir } = require("node-module-dir");
const dir = findNodeModuleDir("package-name");
Licensed under the Apache License, Version 2.0