Installations
npm install find-pkg-dir
Developer Guide
Typescript
No
Module System
N/A
Node Version
12.3.1
NPM Version
6.9.0
Score
65.1
Supply Chain
88.8
Quality
75
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
shinnn
Download Statistics
Total Downloads
303,056
Last Day
147
Last Week
538
Last Month
1,713
Last Year
30,787
GitHub Statistics
3 Stars
19 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Bundle Size
3.36 kB
Minified
1.29 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.0
Package Id
find-pkg-dir@2.0.0
Size
2.42 kB
NPM Version
6.9.0
Node Version
12.3.1
Publised On
31 May 2019
Total Downloads
Cumulative downloads
Total Downloads
303,056
Last day
113%
147
Compared to previous day
Last week
4.1%
538
Compared to previous week
Last month
20.5%
1,713
Compared to previous month
Last year
-42.8%
30,787
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
find-pkg-dir
Find the root directory of a Node.js project from a given path
1const findPkgDir = require('find-pkg-dir'); 2 3// When the /Users/shinnn/foo directory contains a package.json file: 4 5findPkgDir('/Users/shinnn/foo'); //=> '/Users/shinnn/foo' 6findPkgDir('/Users/shinnn/foo/bar'); //=> '/Users/shinnn/foo' 7findPkgDir('/Users/shinnn/foo/bar/baz'); //=> '/Users/shinnn/foo'
- It uses
InternalModuleStat
throughrequire.resolve()
as it's faster thanfs.statSync()
. - It checks if a path is file or directory, to avoid mistaking a
package.json
directory as apackage.json
file. - It automatically resolves symbolic links.
Installation
npm install find-pkg-dir
API
1const findPkgDir = require('find-pkg-dir');
findPkgDir(path)
path: string
(a path to start searching from)
Return: string
(absolute path) or null
It finds the first directory containing a package.json
file, recursively looking up, starting with the given path.
When it cannot find any package.json
files finally, returns null
.
1findPkgDir('path/of/non/nodejs/project'); //=> null
Benchmark
find-pkg-dir (this project):
Find from the current directory 6.514971999917179 ms/op avg.
Find from the deep directory 301.970978999976069 ms/op avg.
Resolve symlinks 4.765490400046110 ms/op avg.
Find from the `package.json` directory 33.653173299971968 ms/op avg.
find-pkg + path.dirname():
Find from the current directory 7.597467000037431 ms/op avg.
Find from the deep directory 421.827792199980479 ms/op avg.
Resolve symlinks N/A (operation failed)
Find from the `package.json` directory N/A (operation failed)
find-root:
Find from the current directory 8.991230100020767 ms/op avg.
Find from the deep directory 479.851285400055360 ms/op avg.
Resolve symlinks N/A (operation failed)
Find from the `package.json` directory N/A (operation failed)
pkg-dir:
Find from the current directory 9.322520200069993 ms/op avg.
Find from the deep directory 505.923578500002634 ms/op avg.
Resolve symlinks N/A (operation failed)
Find from the `package.json` directory N/A (operation failed)
License
ISC License © 2018 - 2019 Shinnosuke Watanabe
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
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 'master'
Reason
29 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/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 MoreOther packages similar to find-pkg-dir
pkg-dir
Find the root directory of a Node.js project or npm package
@visulima/package
One Package to rule them all, finds your root-dir, monorepo, or package manager.
top-pkg-dir
Find top most root directory of a Node.js project or npm package.
root-pkg-dir
Find the highest directory with a package.json, starting from from the current working directory.