Skip to main content

How does npx differ from npm?

The difference is in purpose:

  • npm is a package manager. It installs, updates, and removes dependencies, and runs scripts from package.json.
  • npx is a package runner. It runs npm packages without requiring an install, or looks up and runs local binaries in node_modules/.bin.

The practical difference

Actionnpmnpx
Install, then runrequirednot required
Run a local binaryindirectly (via npm run)directly
Run a one-off CLI commandinconvenientconvenient and fast

Example of the difference

With npm:

bash
npm install create-react-app -g create-react-app my-app

With npx:

bash
npx create-react-app my-app

The second option does not install the package permanently, it is downloaded to a temporary directory, run, and removed.


Summary

  • npm installs packages.
  • npx runs packages.

That is the key difference.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.