By default, if no callback is passed a promise is returned.
The following examples assume the code is inside an async
function:
const load = require('load-pkg');
// get the package.json from the cwd
const pkg = await load();
// specify the starting directory to search from
const pkg = await load('foo/bar');
const load = require('load-pkg');
// get the package.json from the cwd
load((err, pkg) => {
console.log(pkg);
});
// specify the starting directory to search from
load('foo/bar', (err, pkg) => {
console.log(pkg);
});
Loads the package.json in process.cwd()
by default:
const load = require('load-pkg');
// the following are equivalent
const pkg = load.sync(process.cwd());
const pkg = load.sync();
Specify a cwd or filepath to start from:
const pkg = require('load-pkg').sync('a/b/c');
- breaking - requires node.js engine of >=8 to support async/await.
- The main export now returns a promise if no callback is passed. There should not be any breaking changes.
Breaking changes
- The main export is now a function that must be called.