UNPKG

1.16 kBMarkdownView Raw
1# find-root
2recursively find the closest package.json
3
4[![Circle CI](https://circleci.com/gh/jden/find-root.svg?style=svg)](https://circleci.com/gh/jden/find-root)
5
6## usage
7Say you want to check if the directory name of a project matches its
8module name in package.json:
9
10```js
11var path = require('path')
12var findRoot = require('find-root')
13
14// from a starting directory, recursively search for the nearest
15// directory containing package.json
16var root = findRoot('/Users/jden/dev/find-root/tests')
17// => '/Users/jden/dev/find-root'
18
19var dirname = path.basename(root)
20console.log('is it the same?')
21console.log(dirname === require(path.join(root, 'package.json')).name)
22```
23
24
25## api
26
27### `findRoot: (startingPath : String) => String`
28
29Returns the path for the nearest directory to `startingPath` containing
30a `package.json` file, eg `/foo/module`.
31
32Throws an error if no `package.json` is found at any level in the
33`startingPath`.
34
35
36## installation
37
38 $ npm install find-root
39
40
41## running the tests
42
43From package root:
44
45 $ npm install
46 $ npm test
47
48
49## contributors
50
51- jden <jason@denizac.org>
52
53
54## license
55MIT. (c) MMXIII AgileMD http://agilemd.com