package-json-discover v1.0.1
package-json-discover
Discover and load package.json files.
Installation
You can install with npm:
npm install package-json-discoverUsage
/path/to/project/index.js :
var pjd = require("package-json-discover");
// will try to load in order (stop on first file found) :
// - /path/to/project/package.json
// - /path/to/package.json
// - /path/package.json
// - /package.json
var packageJson = pjd.load();
// will try to load in order (stop on first file found) :
// - /path/to/project/sub/dir/package.json
// - /path/to/project/sub/package.json
// - /path/to/project/package.json
// - /path/to/package.json
// - /path/package.json
// - /package.json
var packageJson = pjd.load("sub/dir");
console.log(packageJson.version);API
load({string} from)
Loads the closest
package.jsonfile. Thefromarg define the directory where to start discovering. If nopackage.jsonis found within that directory, search will continue on parent directories until the root directory. An error is thrown if nopackage.jsonwere found.The
fromarg can be absolute or relative to the current file. If it is omitted, it is the file where you call or bind theload()function.
package.jsonexistence is verified only once per directory. If you calldiscover()orload()on the/path/to/projectdirectory several times, verification will occur on the first time you call it, and starting from the second time the path is returned directly.Returns the loaded JSON object.
discover({string} from)
Search the closest
package.jsonfile. Thefromarg define the directory where to start discovering. If nopackage.jsonis found within that directory, search will continue on parent directories until the root directory. An error is thrown if nopackage.jsonwere found.The
fromarg can be absolute or relative to the current file. If it is omitted, it is the file where you call or bind theload()function.
package.jsonexistence is verified only once per directory. If you calldiscover()orload()on the/path/to/projectdirectory several times, verification will occur on the first time you call it, and starting from the second time the path is returned directly.Returns the found path.
Author
This project is authored and maintained by Stephen Berquet.
License
Licensed under the MIT License - see the LICENSE file for details