explaingit

sindresorhus/which-command

Analysis updated 2026-05-18

17JavaScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

A cross-platform JavaScript library and CLI that finds the absolute path to a command, like the Unix which command.

Mindmap

mindmap
  root((which-command))
    What it does
      Find executable paths
      Cross platform lookup
    API
      whichCommand
      whichCommandSync
      whichCommandAll
    Tech Stack
      JavaScript
      ESM
      TypeScript types
    Use Cases
      Check tool installed
      Build CLI tooling
    CLI
      which-command command
      all flag
      silent flag

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Check whether a command line tool is installed before spawning it.

USE CASE 2

Find every matching executable in PATH, not just the first one.

USE CASE 3

Build a custom CLI tool that needs to resolve executables cross-platform.

USE CASE 4

Look up a command from a terminal using the bundled which-command CLI.

What is it built with?

JavaScriptNode.jsESMTypeScript

How does it compare?

sindresorhus/which-commandajaxfnc-yt/d.w.i.falanhuang168/ai-project-workflow
Stars171717
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity1/52/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min
Not stated in the README excerpt reviewed here.

In plain English

which-command is a small JavaScript library that finds the absolute path to a command's executable, similar to the Unix which command. It is useful when you want to locate a tool in the system PATH before running it, check whether something is installed, or build your own command line tooling. It works across platforms, including handling Windows specific details like the PATHEXT environment variable and App Execution Aliases. You install it with npm and import functions such as whichCommand, whichCommandSync, and whichCommandAll. whichCommand returns a promise that resolves to the absolute path of the first matching executable it finds, or undefined if nothing matches. whichCommandSync does the same thing synchronously. whichCommandAll returns every matching executable path found in PATH order rather than just the first one, similar to running which with the all flag, and whichCommandAllSync is its synchronous equivalent. Each function accepts the command name, or a direct path if the name contains a slash or backslash, in which case it is resolved directly instead of being searched for in PATH. Options let you customize the working directory used to resolve relative paths, override the PATH string that gets searched, and on Windows, override the list of executable file extensions normally read from PATHEXT. Empty PATH entries are intentionally ignored rather than treated as the current directory, since implicitly searching the current directory is called out as a security risk. The package also ships a command line tool, so you can run which-command directly from a terminal to look up one or more commands, with an option to list every match instead of just the first, and a silent option that suppresses output while still returning an exit code reflecting whether everything was found. The tool exits with code 1 if any of the given commands cannot be located. The README also compares it to the older node-which package, noting that this library returns undefined instead of throwing when nothing is found, deduplicates results from whichCommandAll, ignores empty PATH entries by default for safety, detects Windows App Execution Aliases that node-which skips, and ships as pure ESM with bundled TypeScript types.

Copy-paste prompts

Prompt 1
Help me use which-command in Node.js to check if a CLI tool is installed before running it.
Prompt 2
Show me how whichCommandAll differs from whichCommand and when to use each.
Prompt 3
Explain how Windows App Execution Aliases are handled by this library versus node-which.
Prompt 4
Help me build a small CLI wrapper around whichCommandSync.

Frequently asked questions

What is which-command?

A cross-platform JavaScript library and CLI that finds the absolute path to a command, like the Unix which command.

What language is which-command written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, ESM.

What license does which-command use?

Not stated in the README excerpt reviewed here.

How hard is which-command to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is which-command for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.