https://github.com/situ2001/which-npm
A command-line utility that helps you locate the package.json file that a specific file or directory belongs to.
https://github.com/situ2001/which-npm
Last synced: 5 months ago
JSON representation
A command-line utility that helps you locate the package.json file that a specific file or directory belongs to.
- Host: GitHub
- URL: https://github.com/situ2001/which-npm
- Owner: situ2001
- License: mit
- Created: 2025-05-03T12:24:26.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-05-03T12:46:53.000Z (5 months ago)
- Last Synced: 2025-05-03T13:37:52.808Z (5 months ago)
- Language: TypeScript
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# which-npm
`which-npm` is a command-line utility that helps you locate the package.json file that a specific file or directory belongs to.
## Installation
```bash
npm install -g which-npm
# or simply run through npx
npx which-npm
```## Usage
```bash
# If no path is provided, the current working directory is used.
which-npm [path] [options]
```### Examples
Basic usage (displays package name):
```bash
which-npm
# my-awesome-package
```Show the absolute path to the package.json file:
```bash
which-npm -p
# /Users/username/projects/my-awesome-package/package.json
```Show the relative path from `./dist/index.js` to the package.json file:
```bash
which-npm ./dist/index.js --path-relative
# ../package.json
```Display the entire package.json content:
```bash
which-npm --json
# { "name": "my-awesome-package", "version": "1.0.0", ... }
```Recursively find all parent package.json files:
```bash
which-npm -r
# my-awesome-package
# parent-workspace
# root-project
```### Options
For a full list of options, run:
```bash
which-npm --help
```## Use Cases
- Identify which package *a file belongs to* in monorepos and print the package name, path or json content
- Find the nearest `package.json` when working in *deeply nested* directories## License
MIT