npx: Run Without Installing

npm installs; npx runs

npm is about installing packages. npx (which comes bundled with npm) is about running a package's command — and it can do so even if the package isn't installed yet, fetching it temporarily just for that one run. It's perfect for one-off tasks and for tools you don't want cluttering your system.

The classic use: starting a new project

The best example is a project generator. You only need it once, to create the project — installing it permanently would be wasteful. So you npx it:

Create a new project, no install needed

Terminal
$ npm create astro@latest
$ # which runs, under the hood:
$ npx create-astro
In VS Code
  1. Open the terminal (Ctrl+`) in the folder where you want the project
  2. Run the command
  3. npx downloads the generator, runs it once, and doesn't leave it lying around

Many 'create' commands (npm create astro, npm create vite) are friendly wrappers around npx running a one-off generator.

Running this project's own tools

When a tool is installed locally (listed in package.json), npx is the tidy way to run it directly. It looks in your project's node_modules/.bin first, so you get the exact version this project pins — not some other version on your machine.

Run a locally-installed tool

Terminal
$ npx astro --version      # the Astro version THIS project uses
$ npx wrangler whoami      # check your Cloudflare login (deploy tool)
In VS Code
  1. Run these in the integrated terminal
  2. Because both astro and wrangler are in this project's devDependencies, npx finds and runs the local copies

This is why npx astro and a 'astro' script in package.json run the same version — both resolve to node_modules/.bin first.

npx vs npm install -g

The two are easy to confuse. The difference is permanence:

  • npm install -g sometool — installs the tool permanently and machine-wide. Good for something you genuinely use across many projects, but it sits there forever and can drift out of date or clash between projects.
  • npx sometool — runs it now, fetching it on the fly if needed, and leaves nothing installed. Great for occasional tools and for always getting a current version.

Rule of thumb: reach for npx for one-off and project-local commands; only install globally (-g) the handful of tools you truly use everywhere. Fewer global installs means fewer "which version am I even running?" surprises.

A quick safety note

Because npx can download and execute code, only run packages you trust — the same common sense you'd apply before installing anything. For well-known tools (Astro, Wrangler, ESLint and the like) it's the standard, convenient way to run a one-off command.

Up next: keeping your installed packages current and secure with npm outdated, npm update and npm audit.

FAQ

Frequently Asked Questions

What is npx?
A command (bundled with npm) that runs a package's command-line tool without installing it permanently — ideal for one-off tasks like npx create-astro.
How is npx different from npm install -g?
npm install -g installs a tool machine-wide so it stays around. npx runs it once (downloading temporarily if needed), which avoids cluttering your system with global packages and version conflicts.
Where does npx find the command?
It checks your project's node_modules/.bin first, so npx astro runs the exact Astro version this project pins. If it isn't installed locally, npx fetches it temporarily from the registry.
Is npx safe to run?
It downloads and executes code, so only run packages you trust. For well-known tools (astro, wrangler, eslint) it's the standard, convenient way to run a one-off command.