Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including package.root.finder with all npm packages installed. Try it out:

var packageRootFinder = require("package.root.finder")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

package.root.finder v0.1.2

Enables to find the first parent package in the path hierarchy

package.root.finder

dependencies devDependency Status

Enables to find the first package in the path hierarchy. It checks recursively for a package.json beginning in the first directory of its path.

Bower information are completed with the directory property normaly stored in the .bowerrc file.

Take a look to the TODO if you want to help towards the next steps.

Installation

Node Dependency

Execute following line

npm install package.root.finder@0.1.x --save

Require module

var root = require('package.root.finder');

Usage

Returns an Object with following properties:

  • name: the name of the parent module
  • directory: the directory of the parent module
  • package: the parent module's package.json content
  • bower: the parent module's bower.json content or false if no bower is used. Also holds the directory property.
  • path: absolut path to the parent module directory

Access the values with the point notation:

var root = require('package.root.finder');

// get parent module's name
root.name
// or
root.package.name

// get root path
root.path

// get bower directory
root.bower.directory

Methods:

  • require: the same as node's native require method, but loads the wanted package from the root package dependencies. Awaits a String as argument: 'mypackage' or '../root/folder/somefile', '../package.json'
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free