I will complement and highlight some things in relation to another answer...
What is NPX?
NPX is an NPM package runner that makes it really easy to install any type of node executable that would normally have been installed using NPM. If NPM is a package manager (manager), NPX is a executioner, so the X at the end of the acronym. The X
comes from andXecutor.
NPX was developed by Kat Marcán, currently maintained by NPM, which was recently purchased by Github. NPX is a binary that has been present in NPM since version 5.2.
Why use the NPX?
There are several ways to install Node.js packages, you can place them locally (local for the project) or install globally (in the user environment).
Sometimes instead of using one of the above two installation methods, you can just use the package and that’s it.
Sometimes you may just want to try a list of packages as you may not know exactly what you need.
In such cases, instead of installing locally or globally, you can go straight to running these packages with NPX.
How it works?
When you run a package using NPX, it looks for the package on local registry and global and then runs the package.
If the package is not yet installed, NPX downloads the package files and install the package, but only store the cached files instead of saving them, that is, contradicting what was said in the other answer:
already npx it will use the package without having to download on your machine,
To use NPX, you would run a command like this:
npx some-package
A great way to see how fast NPX works is to create a reaction application using:
$ npx create-react-app my-app
The above command will generate a app React, so-called my-app
, in the path where the command was executed using the package create-react-app
. The NPX then:
- Search for the package in your environment locally (
node_modules
of the project).
- If not found, look for the package on your system (
node_modules
global).
- If not found, NPX downloads the files and executes the command to create a new app React, using only that command line.
As shown above, NPX does not only search on the npmjs, as search from within the node_modules
of the project also or even in the node_modules
before going online to fetch the packages and run.
In the React example, have the react-native cli
or create-react-app
on the machine takes up space and these libraries are updated very fast, so it doesn’t pay to keep them on the machine. The command create-react-app
, for example, it is done once and then never again, unless you start another project.
Observing
One disadvantage of NPX is that it needs to search the packages, whether they are installed or not, before actually running them. All that path I have mentioned (1, 2 and 3) is checked by the NPX script. This can be an overload when you need to do things very quickly, especially if the packages should be searched and/or downloaded to then yes to run.
Source:
npm is for you to manage packages by installing locally, globally or by removing them, npx is for you to run without installing, the command
react-native run-android
only possible after a global installation, e.g..:nps install -G packageName
– Denis Rudnei de Souza
@Denisrudneidesouza could write a reply with more details, please? (:
– Felipe Avelar