Skip to content

Allows the user to locate the root directory, of a Node application set up using npm, from a specified directory by traversing upwards until the root is located.

Notifications You must be signed in to change notification settings

Tabaci/closest-root

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

closest-root

This npm module allows the user to locate the closest npm root directory from a specified path.

Notice

It is assumed that there is a 'package.json' file located at the root of the application (or module). This means that we cannot have files called 'package.json' in the traversal path, as that will then be viewed as a correct root directory.

What we do know for sure, however, is that according to an issue for npm on GitHub, the name of the 'package.json' file will most certainly not change anytime soon. As such, it is imperative that any other files that need to be called 'package.json' are moved to another directory, where it does not interfere with this module

Installation

$ npm install closest-root

Usage

const rootDirectory = require('closest-root')(__dirname)

/* This will output the closest root directory from the current file, as 
 * '__dirname' returns the name of the current directory we are inside.
 */
console.log(rootDirectory)

License

This module, and the code therein, is licensed under ISC.

About

Allows the user to locate the root directory, of a Node application set up using npm, from a specified directory by traversing upwards until the root is located.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published