npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

package-root-meta

v0.1.1

Published

Find the nearest package.json and package root from a file path or module URL.

Downloads

29

Readme

package-root-meta

Tiny, dependency-free local package metadata and package-root resolver for Node.js.

Find the package a file belongs to.

Install

npm install package-root-meta

Requires Node.js 18 or newer.

Usage

ESM

import { packageJsonPath, packageMeta, packageMetaSync } from "package-root-meta";

const meta = await packageMeta(import.meta.url);

console.log(meta.root);              // package root directory
console.log(meta.path);              // package.json path
console.log(meta.packageJson.name);  // package name
console.log(meta.packageJson.version);

const syncMeta = packageMetaSync(import.meta.url);
const packagePath = packageJsonPath(import.meta.url);

CommonJS

const { packageMeta, packageMetaSync } = require("package-root-meta");

async function main() {
  const meta = await packageMeta(__filename);

  console.log(meta.root);
  console.log(meta.path);
  console.log(meta.packageJson.name);
  console.log(meta.packageJson.version);

  const syncMeta = packageMetaSync(__filename);
}

main();

File paths, directories, and file: URLs

All of these forms are supported:

packageMeta("./src");
packageMeta("/absolute/path/to/src/file.js");
packageMeta(import.meta.url);

The resolver walks upward from the supplied location until it finds the nearest package.json. That means nested packages in a monorepo resolve to their own package boundary rather than the repository root.

If no location is supplied, the current working directory is used:

const meta = packageMeta();

API

packageMeta(location?)

Finds the nearest package.json from a file path, directory, or file: URL.

Returns:

  • root — absolute directory containing the nearest package.json
  • path — absolute path to that package.json
  • packageJson — parsed package metadata

packageJsonPath(location?)

Returns the absolute path to the nearest package.json without parsing the file. This is useful when a caller only needs the package boundary path.

packageMetaSync(location?)

Synchronous version of packageMeta with the same input and return shape.

Design

  • Zero runtime dependencies
  • ESM and CommonJS
  • TypeScript declarations
  • Node.js 18+
  • Works with monorepos and nested packages
  • Local filesystem only
  • No npm registry access
  • No package-manager assumptions

This package intentionally does one thing: resolve local package boundaries and metadata.

License

MIT