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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yukiakai/resolve-package

v1.1.1

Published

Reliable way to find the root directory of a Node.js package, even in pnpm monorepos.

Readme

@yukiakai/resolve-package

NPM Version NPM Downloads

Build Status codecov

🔍 Reliable way to get the root directory or metadata of a Node.js package — even with pnpm!

@yukiakai/resolve-package helps you find the actual root directory of any installed package in your project (where its package.json is located), and even read that package.json — regardless of whether you use npm, yarn, or pnpm (including with symlinks and virtual stores).


🚀 Why?

Most existing solutions like require.resolve, pkg-dir, or resolve only give you the entry file path — not the actual root directory of the package.
In modern pnpm setups, they often fail or give incorrect results due to symlinks and virtual folders.

This library solves it by resolving the entry file, then walking up the directory tree to find the real package.json.


📦 Installation

npm install @yukiakai/resolve-package
# or
pnpm add @yukiakai/resolve-package
# or
yarn add @yukiakai/resolve-package

🔧 Usage

ESM / TypeScript

import { resolvePath, resolveMetadata } from '@yukiakai/resolve-package';

const rootPath = resolvePath('lodash');
const meta = resolveMetadata('lodash');

console.log(rootPath);
// → /absolute/path/to/node_modules/.pnpm/[email protected]/node_modules/lodash

console.log(meta.name, meta.version);
// → lodash 4.17.21

CommonJS

const { resolvePath, resolveMetadata } = require('@yukiakai/resolve-package');

console.log(resolvePath('express'));
console.log(resolveMetadata('express'));

🧩 API

resolvePath(pkgName: string, basedir?: string): string | null

  • Returns absolute path to the root folder of the given package (where its package.json is).
  • Returns null if the package cannot be resolved.

resolveMetadata(pkgName: string, basedir?: string): object | null

  • Returns parsed contents of the package's package.json
  • Returns null if not found or invalid

✅ Features

  • Works with pnpm, npm, and yarn
  • Handles symlinks, hoisted, and virtual stores
  • No assumptions about project layout

📂 Example output (with pnpm):

resolvePath('vite');
// → /home/user/project/node_modules/.pnpm/[email protected]/node_modules/vite

resolveMetadata('vite');
// → { name: 'vite', version: '5.1.0', ... }

🧪 Run Tests

npm run test

Uses Vitest.


❓ FAQ

Q: Why not just use require.resolve()?
A: It only gives you the main file (some/folder/index.js, etc.), not the folder containing package.json. Also, it doesn't work correctly with ESM modules.

Q: Does it work with workspaces / monorepos?
A: Yes. It uses resolve under the hood, and always finds the correct installed location.


📦 Changelog

See full release notes in CHANGELOG.md


📄 License

MIT © 2025 Yuki Akai