Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

find-root

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Issues
File Explorer

Advanced tools

find-root

find the closest package.json

    1.1.0latest

Version published
Maintainers
1
Weekly downloads
8,354,154
decreased by-7.17%

Weekly downloads

Readme

Source

find-root

recursively find the closest package.json

Build Status

usage

Say you want to check if the directory name of a project matches its module name in package.json:

const path = require('path') const findRoot = require('find-root') // from a starting directory, recursively search for the nearest // directory containing package.json const root = findRoot('/Users/jsdnxx/Code/find-root/tests') // => '/Users/jsdnxx/Code/find-root' const dirname = path.basename(root) console.log('is it the same?') console.log(dirname === require(path.join(root, 'package.json')).name)

You can also pass in a custom check function (by default, it checks for the existence of package.json in a directory). In this example, we traverse up to find the root of a git repo:

const fs = require('fs') const gitRoot = findRoot('/Users/jsdnxx/Code/find-root/tests', function (dir) { return fs.existsSync(path.resolve(dir, '.git')) })

api

findRoot: (startingPath : string, check?: (dir: string) => boolean) => string

Returns the path for the nearest directory to startingPath containing a package.json file, eg /foo/module.

If check is provided, returns the path for the closest parent directory where check returns true.

Throws an error if no package.json is found at any level in the startingPath.

installation

> npm install find-root

running the tests

From package root:

> npm install > npm test

contributors

  • jsdnxx

license

MIT. (c) 2017 jsdnxx

Keywords

FAQs

What is find-root?

find the closest package.json

Is find-root popular?

The npm package find-root receives a total of 7,904,290 weekly downloads. As such, find-root popularity was classified as popular.

Is find-root well maintained?

We found that find-root demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 29 Jun 2017

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc