npm is two things really, first; it is an online repository for the publishing of open-source Node.js projects; second, it is a command-line utility for interacting with the said repository that aids in package installation, version management, and dependency management.
Since version email@example.com - See Release Notes, npx is pre-bundled with npm.
Just like npm, npx is a CLI tool but with special use cases. npx is meant to make it easy to use CLI tools and other executables hosted on the npm registry.
Most globally installed packages in node are executables.
Instead of globally installing node executable packages that you will likely use less often, you can save yourself disk space and simply run them with npx when you need it. This means you can use any node executable package on npm registry with having to install it.
For example, I don't have to install create-react-app globally on my machine and no worries about updates likewise because anytime I run
npx create-react-app, npx will always look up the npm registry and run the create-react-app with its latest version.
Installing npm packages globally most times requires sudo (administrative user right). With npx you can simply run a node executable anywhere without sudo.
You don't have to install a CLI tool from npm registry when you only want to give it a try.
You can also use npx to execute your scripts without adding $PATH variables.
Interestingly, you can combine npx superpowers with node package executable on npm registry which installs a node binary into your project (so you can have a local version of node that is different than your system's, and manage node like a normal dependency) just like nvm.
With this combination, you can run commands with different Node.js versions.
npx node@6 <package/command>
Running this should return a path to the
$ which npx
If nothing is returned, it means you don't have a version of npm greater than firstname.lastname@example.org running on your machine. The best bet is to upgrade your npm.
npm install -g npm@latest
- Install Node.js.
- See email@example.com Release Notes
- Install npm
- Install node via nvm My Opinion: The best way to install node.
Start using npx today