Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.19 KB

.verb.md

File metadata and controls

64 lines (42 loc) · 1.19 KB

Usage

async

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');

async callback

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); 
});

sync

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');

Release history

v4.0.0

  • 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.

v2.0.0

Breaking changes

  • The main export is now a function that must be called.