4

This question is about understanding how the npx command works and what it exactly does under the hood. (The documentation does not really help - see below)

From the documentation:

Installation-less command execution

There is another great feature of npx, which is allowing to run commands without first installing them.

Great. Let's try running some command without installation:

npx node@6 -v

And in result one gets:

Need to install the following packages:
  node@6
Ok to proceed? (y)

So there is anyway installation going on. And one could see that something gets installed with npm cache ls.

If we run the command npx node@6 -v again, there won't be a prompt asking for installation. That means the installation (that didn't happen in the first place) persists. And now one could execute the command even without connection to the internet/npm.

For a person who does not know all nuts and bolts of the npm it is kind of strange to find "installation-less execution", which asks for installation.

Could some one give more logical explanation like: when you execute npx node@6 -v this and that happens under the hood, this package will be downloaded and unpacked there ... then executed ... then deleted/or persists for so long ... and so on.

What if I run npx package today (and it gets "installed") and I run the command in 3 months? Would npx check if there is a newer version or would it call the "installed" one? Is there a documentation on that?

Alexander Mihailov
  • 1,050
  • 1
  • 12
  • 19

0 Answers0