Node.js, npm, npx, yarn - huh?

npm basic nodejs javascript npx yarn
Node.js, npm, npx, yarn - huh?

Framework/Language: Node.js
Level: Beginners

What you will build/learn

This Codelab includes concepts/tools explanation and code snippets. To keep it simple, I have tried my best to explain things in the easiest way possible. Also, I have added some GIFs so that you can see those snippets in action.


Scope & Preferred for: 

This Codelab has been designed especially for those who are just beginning with Node and have some confusion about buzz words like npm, npx, node etc. 


Things you will learn

What is:

  • Node.js
  • NPM
  • Yarn 
  • NPX

Tools you will require

  • A computer/laptop with an internet connection. 

 

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

3