package-json-discover
Discover and load package.json
files.
Installation
You can install with npm
:
npm install package-json-discover
Usage
/path/to/project/index.js :
var pjd = ; // will try to load in order (stop on first file found) :// - /path/to/project/package.json// - /path/to/package.json// - /path/package.json// - /package.jsonvar packageJson = pjd; // will try to load in order (stop on first file found) :// - /path/to/project/sub/dir/package.json// - /path/to/project/sub/package.json// - /path/to/project/package.json// - /path/to/package.json// - /path/package.json// - /package.jsonvar packageJson = pjd; console;
API
load([{string} from])
Loads the closest
package.json
file. Thefrom
arg define the directory where to start discovering. If nopackage.json
is found within that directory, search will continue on parent directories until the root directory. An error is thrown if nopackage.json
were found.The
from
arg can be absolute or relative to the current file. If it is omitted, it is the file where you call or bind theload()
function.
package.json
existence is verified only once per directory. If you calldiscover()
orload()
on the/path/to/project
directory several times, verification will occur on the first time you call it, and starting from the second time the path is returned directly.Returns the loaded JSON object.
discover([{string} from])
Search the closest
package.json
file. Thefrom
arg define the directory where to start discovering. If nopackage.json
is found within that directory, search will continue on parent directories until the root directory. An error is thrown if nopackage.json
were found.The
from
arg can be absolute or relative to the current file. If it is omitted, it is the file where you call or bind theload()
function.
package.json
existence is verified only once per directory. If you calldiscover()
orload()
on the/path/to/project
directory several times, verification will occur on the first time you call it, and starting from the second time the path is returned directly.Returns the found path.
Author
This project is authored and maintained by Stephen Berquet.
License
Licensed under the MIT License - see the LICENSE file for details