run
npm exec (npx)
Runs a package's binary from a local install, the cache, or on-the-fly from the registry without a global install. `npx` is the shell-friendly shim; both are equivalent in npm 10+.
npm exec -- <pkg>[@<version>] [args] | npx <pkg> [args] Common flags
| Flag | Purpose |
|---|---|
| --package <pkg> (-p) | Specify the package to fetch when the bin name differs |
| --yes (-y) | Auto-accept installing missing packages |
| --no | Refuse to install a missing package |
| --call <cmd> (-c) | Run an arbitrary shell command with node_modules/.bin on PATH |
| --workspace <name> (-w) | Execute inside a specific workspace |
Examples
npx create-vite my-app Run a create-* package one-off, no global install
npm exec -- eslint src/ Same as `npx eslint` — uses the local devDependency
npx -p typescript@5 -c 'tsc --version' Pin a specific version for a one-shot call
Gotcha
npx prefers the local node_modules/.bin over the registry, so a stale local install can shadow the version you meant. Use `-p pkg@version` to force a specific remote version or a scoped bin name.
Related commands
npm run
Executes a script from the `scripts` block of package.json in a shell where node_modules/.bin is on PATH. Alias: `run-script`; running `npm run` with no arg lists every available script.
npm install --global
Installs a package into the global prefix so its bin scripts are on your PATH system-wide. Global installs live outside any project's node_modules.
npm install
Installs a package (and its dependencies), adding it to package.json and refreshing package-lock.json. Without arguments, installs everything already declared in the current project's package.json.
npm start
Shortcut for `npm run start` — runs the `start` script from package.json. If no `start` script is defined, npm falls back to `node server.js`.
npm test
Shortcut for `npm run test` — runs the `test` script from package.json. Aliases: `npm t`, `npm tst`.