When am teaching my brother react.js he asked me,
- What is NPX and why do we need NPX?
- Why it's important and why I recommended it as a best practice for workflow?
In the blog post am trying to make my brother a clean understanding of NPX and show its advantage and use-cases where he needs it. So am breaking down the questions and show him how it's helpful with a simple example.
We know about utility tools, Utility software is system software designed to help analyze, configure, optimize or maintain a computer. A single piece of utility software is usually called a utility or tool.
What is the difference between NPX and NPM?
NPM: Node Package Manager is the official package manager used for node.js development. it is an online repository for the publishing of open-source Node.js projects. For a clear understanding, PIP is the official package manager for python development. It is a command-line (CLI) utility tool for interacting with the repository that aids in package installation, version management, dependency management, etc.
NPX: NPX is also a command-line (CLI) tool that makes it easy to use our NPM. Since NPM version 5.2.0, NPX is pre-bundled with NPM. NPX is a command provided by npm to enable the execution of locally installed command-line tools directly from the command line.
Example shows the difference between NPM and NPX.
npm i -g create-react-app
Running the above command will install create-react-app package in your machine globally.
npx create-react-app ProjectName
Running the above command will create a react project using create-react-app and set the project name as "ProjectName".
More clear example
How to check your internet speed using NPX utility tool?
Run the below command in any directory, you can see that there is no directory called "node_modules" or a package.json file is generated in your current directory. Yes this is an advantage that we can use for many scenarios and benefit from it
How to check your IP address using NPX?
Some of the best package to exercise this workflow
wifi-password-cli: Get current wifi password
npkill: Easily find and remove old and heavy node_modules folder
depcheck: Check your npm module for unused dependencies
Brother says "enough" and I didn't answer the two questions he asked but he understands what he needs right now. We agreed on a plan to expand this guide when both of us have something new related to NPX and will be updated in this article accordingly.