Find the root directory of a Node.js project or npm package
Installations
npm install pkg-dir
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.18.2
NPM Version
9.2.0
Score
99.6
Supply Chain
82.4
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (81.52%)
TypeScript (18.48%)
Developer
sindresorhus
Download Statistics
Total Downloads
13,580,889,520
Last Day
10,774,408
Last Week
48,316,782
Last Month
217,496,228
Last Year
2,978,508,931
GitHub Statistics
240 Stars
37 Commits
24 Forks
7 Watching
1 Branches
9 Contributors
Bundle Size
1.45 kB
Minified
576.00 B
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
8.0.0
Package Id
pkg-dir@8.0.0
Unpacked Size
4.81 kB
Size
1.97 kB
File Count
5
NPM Version
9.2.0
Node Version
18.18.2
Publised On
03 Nov 2023
Total Downloads
Cumulative downloads
Total Downloads
13,580,889,520
Last day
-4.8%
10,774,408
Compared to previous day
Last week
-15.6%
48,316,782
Compared to previous week
Last month
3.5%
217,496,228
Compared to previous month
Last year
3.7%
2,978,508,931
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
pkg-dir
Find the root directory of a Node.js project or npm package
Install
1npm install pkg-dir
Usage
/
└── Users
└── sindresorhus
└── foo
├── package.json
└── bar
├── baz
└── example.js
1// example.js 2import {packageDirectory} from 'pkg-dir'; 3 4console.log(await packageDirectory()); 5//=> '/Users/sindresorhus/foo'
API
packageDirectory(option?)
Returns a Promise
for either the project root path or undefined
if it could not be found.
packageDirectorySync(options?)
Returns the project root path or undefined
if it could not be found.
options
Type: object
cwd
Type: string
Default: process.cwd()
The directory to start searching from.
Related
- pkg-dir-cli - CLI for this module
- pkg-up - Find the closest package.json file
- find-up - Find a file by walking up parent directories
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/pkg-dir/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/pkg-dir/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More