What is NPX?
Tags: npm, todayilearned, todayisearched, bash
Published: 2020-02-03 23:58:02

Sup dudes! 🐱‍🐉

![](https://media.giphy.com/media/KpACNEh8jXK2Q/giphy.gif)

Have you ever installed some global package and needed to use it just a few times? Are you having compatibility problems with the global package because of different versions in multiples projects? Is your machine polluted with many global packages? Worry no more, NPX is here for you.

Today's drops topic is NPX, what is it, what can he do and "why an X, wasn't it NPM?"

## First things first 👍

For those who are using the latest version of npm, the npm@5.2.0 there's a new binary, the npx. Before I explain what the npx does, let's talk about binary packages and installations.

### First: Global and Local installations

Global installations are made when you need to execute the binary from any directory of your machine.

With Local installation, you can only execute it if you are inside the directory your project is. In that way, it will be added to a script in package.json. If it contains a binary it will be added to node_modules/.bin e

## The Problem 👨‍💻

Almost every time when someone needs to install a package globally is because it will be used in another project. But, sometimes we want to only test it, or in many cases, we install it globally because it's suggested on the documentation. The problem is that in the long term your machine gets "dirty" with all those packages, and always when your project will use another version of the package installed globally it will require to change the version.

Another problem is when your package needs to be used in another project, in that case, you will need to install it manually (in case you don't have an autonomous way to solve this). Not at all convenient as just ``npm install``.

## The solution 😊

NPX. It makes possible to execute a local package as if it's global.

Npx will look for the binary in the node_modules/.bin, if it doesn't find the binary, it will go further down in the files until it finds. If in a case it doesn't find, it will install the binary, execute it and soon after will uninstall it.

So let's say you have a project that you used create-react-app, will be a long time until you run create-react-app again, so why not use npx create-react-app? Or even better, why not use it on your README.md so the people using your project doesn't need to install create-react-app. 0 Commitment!

To use with create-react-app for instance, just type ``npx create-react-app my-awesome-app``

![](https://media.giphy.com/media/3o7WTAkv7Ze17SWMOQ/giphy.gif)

## Bonus 

### Why npx has a 'x'? 🤔

Well, the x mostly likely is for eXecute, but we don't have a clear answer for now.



I hope you guys enjoyed this quick article about npx.

![](https://media.giphy.com/media/TFYyfFrqxuExEM5r04/giphy.gif)

REFERENCES: https://www.youtube.com/watch?v=Sf6JcMz_shU

https://www.npmjs.com/package/npx

https://www.linkedin.com/pulse/npx-uma-alternativa-para-pacotes-globais-e-outras-angelo-medeiros/

https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm