Find the nearest package.json by recursively crawling parent directories
npm install find-nearest-package-jsonFind the nearest package.json by recursively crawling parent directories
``sh`
yarn add find-nearest-package-json
`js
import {
findNearestPackageJson,
findNearestPackageJsonSync
} from 'find-nearest-package-json'
async function runAsync() {
const packageJsonNearestCwd = await findNearestPackageJson()
const packageJsonNearestGivenDir = await findNearestPackageJson('/tmp/some-project/some-dir')
console.log(packageJsonNearestGivenDir.path)
console.log(packageJsonNearestGivenDir.data)
}
function runSync() {
const packageJsonNearestCwd = findNearestPackageJsonSync()
const packageJsonNearestGivenDir = findNearestPackageJsonSync('/tmp/some-project/some-dir')
console.log(packageJsonNearestGivenDir.path)
console.log(packageJsonNearestGivenDir.data)
}
``