1. pkg-up
Find the closest package.json file
pkg-up
Package: pkg-up
Created by: sindresorhus
Last modified: Sat, 04 Nov 2023 09:16:15 GMT
Version: 5.0.0
License: MIT
Downloads: 36,141,058
Repository: https://github.com/sindresorhus/pkg-up

Install

npm install pkg-up
yarn add pkg-up

pkg-up

Find the closest package.json file

Install

 npm install pkg-up

Usage

/
└── Users
    └── sindresorhus
        └── foo
            ├── package.json
            └── bar
                ├── baz
                └── example.js
 // example.js
import {pkgUp} from 'pkg-up';

console.log(await pkgUp());
//=> '/Users/sindresorhus/foo/package.json'

API

pkgUp(options?)

Returns a Promise<string> for the file path, or Promise<undefined> if it could not be found.

pkgUpSync(options?)

Returns the file path, or undefined if it could not be found.

options

Type: object

cwd

Type: string
Default: process.cwd()

The directory to start from.

  • read-pkg-up - Read the closest package.json file
  • pkg-dir - Find the root directory of an npm package
  • find-up - Find a file by walking up parent directories

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code