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

which-command

v0.1.0

Published

Find the absolute path to a command's executable, like the Unix `which` command

Readme

which-command

Find the absolute path to a command's executable, like the Unix which command

Useful for locating an executable in PATH before spawning it, checking whether a tool is installed, or building your own CLI tooling.

Works cross-platform, including Windows PATHEXT handling and App Execution Aliases.

Install

npm install which-command

Usage

import {whichCommand, whichCommandSync, whichCommandAll} from 'which-command';

await whichCommand('node');
//=> '/usr/local/bin/node'

await whichCommand('does-not-exist');
//=> undefined

whichCommandSync('node');
//=> '/usr/local/bin/node'

await whichCommandAll('node');
//=> ['/usr/local/bin/node', '/opt/homebrew/bin/node']

API

whichCommand(command, options?)

Returns a Promise for the absolute path to the first matching executable, or undefined if not found.

whichCommandSync(command, options?)

Same as whichCommand(), but synchronous.

whichCommandAll(command, options?)

Returns a Promise for an array of the absolute paths to all matching executables in PATH order, or an empty array if none are found. Like which -a.

whichCommandAllSync(command, options?)

Same as whichCommandAll(), but synchronous.

command

Type: string

The command name to look for, or a path to check directly.

If it contains a directory separator (like ./foo or /usr/bin/foo), it's resolved directly instead of being searched for in PATH.

options

Type: object

cwd

Type: string
Default: process.cwd()

The directory to resolve relative paths against.

Relative path entries and commands that contain a directory separator are resolved against this. On Windows, this directory is also searched before PATH.

path

Type: string
Default: process.env.PATH

The PATH to search.

Empty entries are ignored. Unlike a POSIX shell, an empty entry is not treated as the current directory, since implicitly searching the current directory is a security risk.

pathExt

Type: string
Default: process.env.PATHEXT

The executable file extensions to look for, as a ;-separated string.

Only used on Windows. Corresponds to the PATHEXT environment variable.

CLI

$ npx which-command --help

  Usage
    $ which-command <command> …

  Options
    --all, -a     List all matching paths, not just the first
    --silent, -s  Suppress output; the exit code still reflects whether all commands were found

  Examples
    $ which-command node
    /usr/local/bin/node

    $ which-command --all node
    /usr/local/bin/node
    /opt/homebrew/bin/node

  Exits with code 1 if any of the commands could not be found.

FAQ

How is it better than the which package?

  • Returns undefined when a command is not found, instead of throwing.
  • whichCommandAll() deduplicates results, so duplicate PATH entries don't produce duplicate matches.
  • Safer by default: empty PATH entries are ignored instead of implicitly searching the current directory.
  • Finds Windows App Execution Aliases (like the python and winget stubs in WindowsApps), which which skips.
  • Modern: pure ESM with bundled TypeScript types.