sindresorhus/which-command — explained in plain English
Analysis updated 2026-05-18
Check whether a command line tool is installed before spawning it.
Find every matching executable in PATH, not just the first one.
Build a custom CLI tool that needs to resolve executables cross-platform.
Look up a command from a terminal using the bundled which-command CLI.
| sindresorhus/which-command | ajaxfnc-yt/d.w.i.f | alanhuang168/ai-project-workflow | |
|---|---|---|---|
| Stars | 17 | 17 | 17 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | easy | moderate | easy |
| Complexity | 1/5 | 2/5 | 3/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
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.
A cross-platform JavaScript library and CLI that finds the absolute path to a command, like the Unix which command.
Mainly JavaScript. The stack also includes JavaScript, Node.js, ESM.
Not stated in the README excerpt reviewed here.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.