https://github.com/ambiere/project-root
Zero dependencies utility, that helps you find the root of your project.
https://github.com/ambiere/project-root
directory npm package-json parent path project root
Last synced: about 2 months ago
JSON representation
Zero dependencies utility, that helps you find the root of your project.
- Host: GitHub
- URL: https://github.com/ambiere/project-root
- Owner: ambiere
- License: mit
- Created: 2024-04-04T17:21:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-05T11:42:08.000Z (about 2 years ago)
- Last Synced: 2025-10-02T13:56:07.832Z (9 months ago)
- Topics: directory, npm, package-json, parent, path, project, root
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Funding: .github/funding.yml
- License: license
- Code of conduct: .github/code_of_conduct.md
Awesome Lists containing this project
README
# project-root
> Tiny and zero dependencies utility, that finds the root of npm project.
[](https://github.com/ambiere/project-root/actions/workflows/main.yml)
## Install
```bash
npm install @ambiere/project-root
```
## Usage
Example npm project structure:
```txt
/
└── root
├── .git
├── package.json
└── src
├── types
└── index.js
```
Find the root of the project in `index.js` file:
```js
import projectRootDir from "@ambiere/project-root"
const projectRoot = projectRootDir()
console.log(projectRoot) // → /root
```
## API
### `projectRootDir(dir?)`
Return the root directory of the npm project or `undefined` if none could be found.
#### dir:
Type: `string`
Default: `process.cwd`
The directory to start the search.
## License
[MIT license][MIT]
[MIT]: https://github.com/ambiere/project-root/blob/main/license