1 | # find-root
|
2 | recursively 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
|
7 | Say you want to check if the directory name of a project matches its
|
8 | module name in package.json:
|
9 |
|
10 | ```js
|
11 | var path = require('path')
|
12 | var findRoot = require('find-root')
|
13 |
|
14 | // from a starting directory, recursively search for the nearest
|
15 | // directory containing package.json
|
16 | var root = findRoot('/Users/jden/dev/find-root/tests')
|
17 | // => '/Users/jden/dev/find-root'
|
18 |
|
19 | var dirname = path.basename(root)
|
20 | console.log('is it the same?')
|
21 | console.log(dirname === require(path.join(root, 'package.json')).name)
|
22 | ```
|
23 |
|
24 |
|
25 | ## api
|
26 |
|
27 | ### `findRoot: (startingPath : String) => String`
|
28 |
|
29 | Returns the path for the nearest directory to `startingPath` containing
|
30 | a `package.json` file, eg `/foo/module`.
|
31 |
|
32 | Throws 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 |
|
43 | From package root:
|
44 |
|
45 | $ npm install
|
46 | $ npm test
|
47 |
|
48 |
|
49 | ## contributors
|
50 |
|
51 | - jden <jason@denizac.org>
|
52 |
|
53 |
|
54 | ## license
|
55 | MIT. (c) MMXIII AgileMD http://agilemd.com
|