Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

is-npm

sindresorhus34.2mMIT6.1.0TypeScript support: included

Check if your code is running as an npm script

npm, yarn, pnpm, bun, is, check, detect, env, environment, run, script, package-manager

readme

is-npm

Check if your code is running as an npm, yarn, pnpm, or bun script

Install

npm install is-npm

Usage

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

console.table({isPackageManager, isNpm, isYarn, isPnpm, isBun});
$ 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 script.

isYarn

Check if your code is running as a yarn script.

isPnpm

Check if your code is running as a pnpm script.

isBun

Check if your code is running as a bun 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 or yarn script.

Use isPackageManager instead for detecting any package manager.