What is npx and How to Use It

If you're diving into modern JavaScript development, you might come across the term npx.

No, it's not a typo of npm.

It's a separate tool bundled with npm version 5.2.0 and higher, providing a handy way to execute Node.js binaries.

What is npx?

npx allows developers to run commands from locally installed packages without globally installing them.

This promotes a more efficient workflow and cleaner global space.

A few years ago it would be pretty normal to globally install tools on your system before running them.

The magic of npx comes from its ability to run packages that aren't globally installed on your system.

If you attempt to run a package using npx that isn't installed locally, npx will temporarily install and run that package.

How to Use npx

Using npx is incredibly simple, and I guess that is why JS devs love it. Here's how:

1. Run npx:

npx create-next-app

In the example above, npx will either run create-next-app if it is installed or fetch it from the npm registry and run it.

Simple, right? 🚀

2. Specifying a Package Version:

npx create-next-app@13.4.13

In this example, you can pick a specific version in the same way you would if you were using npm install.

Happy coding!

Follow me on Twitter or connect on LinkedIn.

🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉

Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.