# which

> Like which(1) unix command. Find the first instance of an executable in the PATH.

Latest version **7.0.0** (published 2026-05-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install which
pnpm add which
yarn add which
bun add which
```

Provides the command `node-which`.

## Health

**Score 63/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-05-08 |
| First published | 2011-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/which) |
| Module format | CommonJS |
| Node | ^22.22.2 \|\| ^24.15.0 \|\| >=26.0.0 |
| Dependencies | 1 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 352 |
| Author | GitHub Inc. |
| Maintainers | saquibkhan, npm-cli-ops, reggi, owlstronaut |

## Links

- npm: https://www.npmjs.com/package/which
- Repository: https://github.com/npm/node-which
- Homepage: https://github.com/npm/node-which#readme
- Issues: https://github.com/npm/node-which/issues
- npm.io page: https://npm.io/package/which

## Dependencies (1)

- [isexe](https://npm.io/package/isexe.md) ^4.0.0

## Recent versions

- 7.0.0 (latest) — 2026-05-08
- 6.0.1 — 2026-02-10
- 6.0.0 — 2025-11-10
- 5.0.0 — 2024-10-01
- 4.0.0 — 2023-08-29
- 3.0.1 — 2023-05-01
- 3.0.0 — 2022-11-01
- 2.0.2 — 2019-11-18
- 2.0.1 — 2019-10-03
- 2.0.0 — 2019-10-03
- 1.3.1 — 2018-05-25
- 1.3.0 — 2017-08-01
- 1.2.14 — 2017-03-23
- 1.2.13 — 2017-03-23
- 1.2.12 — 2016-11-11
- … 22 more at https://npm.io/package/which/versions

## README

# which

Like the unix `which` utility.

Finds the first instance of a specified executable in the PATH
environment variable.  Does not cache the results, so `hash -r` is not
needed when the PATH changes.

## USAGE

```javascript
const which = require('which')

// async usage
// rejects if not found
const resolved = await which('node')

// if nothrow option is used, returns null if not found
const resolvedOrNull = await which('node', { nothrow: true })

// sync usage
// throws if not found
const resolved = which.sync('node')

// if nothrow option is used, returns null if not found
const resolvedOrNull = which.sync('node', { nothrow: true })

// Pass options to override the PATH and PATHEXT environment vars.
await which('node', { path: someOtherPath, pathExt: somePathExt })
```

## CLI USAGE

Just like the BSD `which(1)` binary but using `node-which`.

```
usage: node-which [-as] program ...
```

You can learn more about why the binary is `node-which` and not `which` 
[here](https://github.com/npm/node-which/pull/67)

## OPTIONS

You may pass an options object as the second argument.

- `path`: Use instead of the `PATH` environment variable.
- `pathExt`: Use instead of the `PATHEXT` environment variable.
- `all`: Return all matches, instead of just the first one.  Note that
  this means the function returns an array of strings instead of a
  single string.

---
_Source: https://npm.io/package/which · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
