2.0.0 • Published 2 years ago

new-find-package-json v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

new-find-package-json

Inspired by find-package-json

This package can find (by default) the nearest package.json (upwards).

Usage

Sync:

const findFileFrom = process.cwd();
for (const file of findSync(findFileFrom)) {
  console.log("found file:", file);
}

Async/await (Promises):

const findFileFrom = process.cwd();
for await (const file of findAsync(findFileFrom)) {
  console.log("found file:", file);
}

Note: it is important to not forget to use for await..of instead of just for..of for findAsync

Options

Options for findSync & findAsync:

IndexNameTypeDefaultDescription
0inputstringnone (required)The path to search from
1basestringprocess.cwd()The path to use as an absolute point if input is not absolute
2fileNamestringpackage.jsonThe Filename to search for

.next will return an object with value and done, where value is the absolute path to the file found and undefined if done is true