npx

What is npx?
`npx` is a tool which executes npm package binaries. In short, its a tool that helps us in running a node package (or a script). For ease, you can relate them with `.exe` or shell scripts `.sh`. Let's look at them with an example: 

How to use?

npx create-react-app naman-app

Here npx will do two things:
Step 1- It checks whether `create-react-app` package is installed globally or not. 
If present then uses it, otherwise... (Hint: Global Packages-> `npm i -g create-react-app`)

Step 2- It checks whether `create-react-app` package is installed locally or not. (Project level)
If present then uses it, otherwise... (Hint: Local Packages-> `npm i --save create-react-app`)

Step 3- It checks whether npmjs.com has that package or not. 
If present then it fetches the package and run it.

You can see above gif. In this, npx downloads ask for permission to download from npmjs.com as I didn't have that installed. 

Discussion

Be the first one to comment!