Find root module with folder and package.json.
This module is very useful to support/find additonal configurations, plugins & extensions for your libraries.
For example, if you have a node module called awesome-module
and want to allow your clients to set configuration parameters. Two most common ways of doing this is via
- custom configuration file - say
.awesomerc
in the projects root folder - a custom entry in root package.json file
babel, eslint and other libraries follow this pattern.
To simply load the root package.json:
var rootModule = require('root-module');
var m = rootModule();
var packageJson = require(m.packageFile);
To locate the custom configuration file:
var rootModule = require('root-module');
var m = rootModule();
var awesomeConfig = m.findFile('.awesomerc');
Install via npm
$ npm install root-module --save
var rootModule = require('root-module');
var m = rootModule();
console.log(m.module);
console.log(m.folder);
console.log(m.packageFile);
var myConfig = m.findFile('my-config.json');