Sup dudes! 🐱🐉
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?"
For those who are using the latest version of npm, the firstname.lastname@example.org there's a new binary, the npx. Before I explain what the npx does, let's talk about binary packages and 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
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
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
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.