Socket
Socket
Sign inDemoInstall

find-root

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    find-root

find the closest package.json


Version published
Maintainers
1
Install size
5.18 kB
Created

Package description

What is find-root?

The find-root npm package is used to find the root directory of a Node.js project or module. This is typically the location where the 'package.json' file is located. It is useful when you have a deeply nested file structure and need to programmatically find the path to the project root.

What are find-root's main functionalities?

Find project root

This feature allows you to find the nearest directory containing a package.json file, which is considered the project's root directory.

const findRoot = require('find-root');
const root = findRoot('/path/to/some/deeply/nested/file');
console.log(root); // prints the path to the nearest directory containing a package.json

Other packages similar to find-root

Readme

Source

find-root

recursively find the closest package.json

Circle CI

usage

Say you want to check if the directory name of a project matches its module name in package.json:

var path = require('path')
var findRoot = require('find-root')

// from a starting directory, recursively search for the nearest
// directory containing package.json
var root = findRoot('/Users/jden/dev/find-root/tests')
// => '/Users/jden/dev/find-root'

var dirname = path.basename(root)
console.log('is it the same?')
console.log(dirname === require(path.join(root, 'package.json')).name)

api

findRoot: (startingPath : String) => String

Returns the path for the nearest directory to startingPath containing a package.json file, eg /foo/module.

Throws an error if no package.json is found at any level in the startingPath.

installation

$ npm install find-root

running the tests

From package root:

$ npm install
$ npm test

contributors

license

MIT. (c) MMXIII AgileMD http://agilemd.com

Keywords

FAQs

Last updated on 21 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc