Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
find-pkg-dir
Advanced tools
Readme
Find the root directory of a Node.js project from a given path
const findPkgDir = require('find-pkg-dir');
// When the /Users/shinnn/foo directory contains a package.json file:
findPkgDir('/Users/shinnn/foo'); //=> '/Users/shinnn/foo'
findPkgDir('/Users/shinnn/foo/bar'); //=> '/Users/shinnn/foo'
findPkgDir('/Users/shinnn/foo/bar/baz'); //=> '/Users/shinnn/foo'
InternalModuleStat
through require.resolve()
as it's faster than fs.statSync()
.package.json
directory as a package.json
file.npm install find-pkg-dir
const findPkgDir = require('find-pkg-dir');
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
.
findPkgDir('path/of/non/nodejs/project'); //=> null
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)
ISC License © 2018 - 2019 Shinnosuke Watanabe
FAQs
Find the root directory of a Node.js project from a given path
The npm package find-pkg-dir receives a total of 681 weekly downloads. As such, find-pkg-dir popularity was classified as not popular.
We found that find-pkg-dir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.