Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
pkg-up
Advanced tools
Package description
The pkg-up npm package is used to find the closest package.json file in the directory tree, starting from a given directory. It is useful for Node.js projects where you need to locate the package.json file of the current project or a related package.
Find the closest package.json
This feature allows you to asynchronously find the nearest package.json file from the current directory.
const pkgUp = require('pkg-up');
(async () => {
const filePath = await pkgUp();
console.log(filePath);
//=> '/Users/sindresorhus/foo/package.json'
})();
Find the closest package.json synchronously
This feature provides a synchronous method to find the nearest package.json file.
const pkgUp = require('pkg-up');
const filePath = pkgUp.sync();
console.log(filePath);
//=> '/Users/sindresorhus/foo/package.json'
Find package.json from a specific directory
This feature allows you to find the nearest package.json file starting from a specific directory.
const pkgUp = require('pkg-up');
(async () => {
const filePath = await pkgUp({cwd: 'some/subdirectory'});
console.log(filePath);
//=> '/Users/sindresorhus/foo/package.json'
})();
find-up is similar to pkg-up but is more generic. It allows you to find files or directories by name, moving upwards from a given directory. It's not limited to package.json files, making it more versatile for different use cases.
read-pkg-up is built on top of pkg-up and not only finds the closest package.json file but also reads and parses it. This package combines the functionality of pkg-up and read-pkg, providing a more comprehensive solution for accessing package information.
look-up is another package that can be used to find files in parent directories, similar to pkg-up. However, it is less focused on package.json files and more on file patterns, which can be useful for different kinds of file searches.
Readme
Find the closest package.json file
$ npm install pkg-up
/
âââ Users
âââ sindresorhus
âââ foo
âââ package.json
âââ bar
âââ baz
âââ example.js
// example.js
const pkgUp = require('pkg-up');
(async () => {
console.log(await pkgUp());
//=> '/Users/sindresorhus/foo/package.json'
})();
Returns a Promise<string>
for the filepath, or Promise<null>
if it couldn't be found.
Returns the filepath, or null
if it couldn't be found.
Type: Object
Type: string
Default: process.cwd()
Directory to start from.
MIT Š Sindre Sorhus
FAQs
Find the closest package.json file
The npm package pkg-up receives a total of 7,796,112 weekly downloads. As such, pkg-up popularity was classified as popular.
We found that pkg-up demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.