The executor of NPX NPM package


The executor of NPX NPM package
When running on the command linenpx cowsay hello, will search local firstnode_modulesIs there any in the directorycowsayModule, if any, execute; if not, temporarily install thecowsayThe module is then executed and deleted after executionhelloIt’s a parameter.

From the above example, we can see that NPX has two functions

  1. Directly call the modules in the execution project
  2. Avoid global installation

Point 2 can give another example, for example, we want to usecreate-react-appCreate areactProject, runningnpx create-react-app my-appDirectly call thecreate-react-appCreate project to avoid global installation

When we want to installvueProject, but do not want to install globallyvue-cliperhaps@vue/cli, which can also be usednpxOf

npx -p vue-cli vue init webpack project


npx -p @vue/cli vue create project

Reference resources: