# lookpath

> The minimum and most straightforward way to check if command exists and where the executable is.

Latest version **1.2.3** (published 2025-01-07) · MIT license · 0 weekly downloads

## Install

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

Provides the command `lookpath`.

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2025-01-07 |
| First published | 2019-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | otiai10 |
| Maintainers | otiai10 |
| Keywords | exec.LookPath, command, exists |

## Links

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

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.2.3 (latest) — 2025-01-07
- 1.2.2 — 2021-07-30
- 1.2.1 — 2021-05-20
- 1.2.0 — 2021-02-27
- 1.1.0 — 2020-07-14
- 1.0.6 — 2020-04-23
- 1.0.5 — 2020-02-07
- 1.0.4 — 2019-12-17
- 1.0.3 — 2019-10-05
- 1.0.2 — 2019-05-30
- 1.0.1 — 2019-05-27
- 1.0.0 — 2019-05-13
- 0.1.1 — 2019-05-13
- 0.1.0 — 2019-05-07
- 0.0.3 — 2019-05-06
- … 2 more at https://npm.io/package/lookpath/versions

## README

# lookpath

[![npm version](https://badge.fury.io/js/lookpath.svg)](https://badge.fury.io/js/lookpath)
[![npm download](https://img.shields.io/npm/dt/lookpath.svg)](https://www.npmjs.com/package/lookpath)
[![Node.js CI](https://github.com/otiai10/lookpath/workflows/Node.js%20CI/badge.svg)](https://github.com/otiai10/lookpath/actions/)
[![CodeQL](https://github.com/otiai10/lookpath/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/otiai10/lookpath/actions/workflows/codeql-analysis.yml)
[![codecov](https://codecov.io/gh/otiai10/lookpath/branch/master/graph/badge.svg)](https://codecov.io/gh/otiai10/lookpath)
[![Maintainability](https://api.codeclimate.com/v1/badges/1cc9237695a7bd8e3d60/maintainability)](https://codeclimate.com/github/otiai10/lookpath/maintainability)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fotiai10%2Flookpath.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fotiai10%2Flookpath?ref=badge_shield)

To check if the command exists and where the executable file is, **WITHOUT** using `child_process`.

```
npm install lookpath
```

# Example usage

```js
const { lookpath } = require('lookpath');

const p = await lookpath('bash');
// "/bin/bash", otherwise "undefined"
```

# Advanced usage

```js
const p = await lookpath('bash', {
  include: ['/home/hiromu/.bin'],
  exclude: ['/mnt']
});
// include: Do scan also under `~/.bin`
// exclude: Do NOT scan under `/mnt`
```

# Motivation

- I don't want to spawn `child_process` in order to kick `which`, `where`, `whereis`, or `command -v`.
    - [node.js - Node - check existence of command in path - Stack Overflow](https://stackoverflow.com/questions/34953168/node-check-existence-of-command-in-path/)
    - [Node.js: Check if a command exists - Gist](https://gist.github.com/jmptable/7a3aa580efffdef50fa9f0dd3d068d6f)
    - [mathisonian/command-exists: node module to check if a command-line command exists - GitHub](https://github.com/mathisonian/command-exists)
- then I checked Go implementation of [`exec.LookPath`](https://golang.org/pkg/os/exec/#LookPath).
    - [src/os/exec/lp_unix.go - The Go Programming Language](https://golang.org/src/os/exec/lp_unix.go?s=928:970#L24)
- so I concluded that scanning under `$PATH` or `$Path` is the best straightforward way to check if the command exists.


# Issues

- https://github.com/otiai10/lookpath/issues

Any feedback would be appreciated ;)


# License

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fotiai10%2Flookpath.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fotiai10%2Flookpath?ref=badge_large)

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