read-closest-package

reads the closest package.json file

MIT License

Downloads
2.1K
Stars
5

read-closest-package

Reads the closest package.json file and parses its JSON.

require('read-closest-package')(function(err, data, filename) {
  console.log(data.version)
  console.log(data.description)
  console.log(filename)
})

Also has a sync API which returns null on any errors:

var closest = require('read-closest-package')

var pkg = closest.sync()
if (pkg) 
  console.log(pkg.version)

Usage

closest([opt], cb)

Looks for the closest package and calls the callback cb with (err, data, filename).

  • cwd the working directory to search up from for the package.json (defaults to process.cwd())
  • filter a filter passed to closest-package

If there was an error finding the pacakge or parsing JSON, err will be non-null.

data = closest.sync([opt])

The same as above, but synchronous. Returns null on any errors.

See Also

License

MIT, see LICENSE.md for details.