LinuxCommandLibrary

npm-bin

TLDR

Show local bin directory

$ npm bin
copy
Show global bin directory
$ npm bin -g
copy
Add local bin to PATH
$ export PATH="$(npm bin):$PATH"
copy

SYNOPSIS

npm bin [options]

DESCRIPTION

npm bin prints the folder where npm will install executables. For local installations, this is typically ./node_modules/.bin; for global, it depends on npm prefix.
Adding the local bin to PATH allows running locally installed tools.

PARAMETERS

-g, --global

Show global bin directory.

EXAMPLE USAGE

$ # Show local bin
npm bin
# Output: /project/node_modules/.bin

# Show global bin
npm bin -g
# Output: /usr/local/bin

# Run local binary
$(npm bin)/eslint .

# Or add to PATH
export PATH="$(npm bin):$PATH"
eslint .
copy

ALTERNATIVES

$ # Use npx instead
npx eslint .

# Or npm exec
npm exec eslint .
copy

CAVEATS

Local bin changes per project. Global path varies by installation method. npx is often simpler for running binaries.

HISTORY

npm bin has been part of npm since early versions, helping developers locate and use locally installed executables.

SEE ALSO

npm(1), npx(1), npm-exec(1), npm-prefix(1)

Copied to clipboard