# is-npm

> Check if your code is running as an npm script

Latest version **6.1.0** (published 2025-09-10) · MIT license · 0 weekly downloads

> **Better alternative:** Use process.env.npm_config_user_agent?.startsWith("npm") — Consider using a lighter alternative

## Install

```sh
npm install is-npm
pnpm add is-npm
yarn add is-npm
bun add is-npm
```

## Health

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

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2025-09-10 |
| First published | 2014-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 66 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | npm, yarn, pnpm, bun, is, check, detect, env, environment, run, script, package-manager |

## Links

- npm: https://www.npmjs.com/package/is-npm
- Repository: https://github.com/sindresorhus/is-npm
- Homepage: https://github.com/sindresorhus/is-npm#readme
- Issues: https://github.com/sindresorhus/is-npm/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/is-npm

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 6.1.0 (latest) — 2025-09-10
- 6.0.0 — 2021-09-18
- 5.0.0 — 2020-05-15
- 4.0.0 — 2019-10-14
- 3.0.0 — 2019-03-11
- 2.0.0 — 2018-03-22
- 1.0.0 — 2014-07-20

## README

# is-npm

> Check if your code is running as an [npm](https://docs.npmjs.com/misc/scripts), [yarn](https://yarnpkg.com/cli/run), [pnpm](https://pnpm.io), or [bun](https://bun.sh) script

## Install

```sh
npm install is-npm
```

## Usage

```js
import {isPackageManager, isNpm, isYarn, isPnpm, isBun} from 'is-npm';

console.table({isPackageManager, isNpm, isYarn, isPnpm, isBun});
```

```sh
$ node foo.js
# ┌──────────────────┬────────┐
# │     (index)      │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ false  │
# │      isNpm       │ false  │
# │     isYarn       │ false  │
# │     isPnpm       │ false  │
# │      isBun       │ false  │
# └──────────────────┴────────┘
$ npm run foo
# ┌──────────────────┬────────┐
# │     (index)      │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true   │
# │      isNpm       │ true   │
# │     isYarn       │ false  │
# │     isPnpm       │ false  │
# │      isBun       │ false  │
# └──────────────────┴────────┘
$ yarn run foo
# ┌──────────────────┬────────┐
# │     (index)      │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true   │
# │      isNpm       │ false  │
# │     isYarn       │ true   │
# │     isPnpm       │ false  │
# │      isBun       │ false  │
# └──────────────────┴────────┘
$ pnpm run foo
# ┌──────────────────┬────────┐
# │     (index)      │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true   │
# │      isNpm       │ false  │
# │     isYarn       │ false  │
# │     isPnpm       │ true   │
# │      isBun       │ false  │
# └──────────────────┴────────┘
$ bun run foo
# ┌──────────────────┬────────┐
# │     (index)      │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true   │
# │      isNpm       │ false  │
# │     isYarn       │ false  │
# │     isPnpm       │ false  │
# │      isBun       │ true   │
# └──────────────────┴────────┘
```

## API

### isNpm

Check if your code is running as an [npm](https://docs.npmjs.com/misc/scripts) script.

### isYarn

Check if your code is running as a [yarn](https://yarnpkg.com/cli/run) script.

### isPnpm

Check if your code is running as a [pnpm](https://pnpm.io) script.

### isBun

Check if your code is running as a [bun](https://bun.sh) script.

### isPackageManager

Check if your code is running as a package manager script (npm, yarn, pnpm, or bun).

### isNpmOrYarn *(deprecated)*

Check if your code is running as an [npm](https://docs.npmjs.com/misc/scripts) or [yarn](https://yarnpkg.com/cli/run) script.

**Use `isPackageManager` instead** for detecting any package manager.

## Related

- [is-npm-cli](https://github.com/sindresorhus/is-npm-cli) - CLI for this module

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