Using NPX as a utility tool for developers - NPX for brother

Using NPX as a utility tool for developers - NPX for brother

A practical guide explains the usage of NPX for those who see NPX for first time.

When am teaching my brother react.js he asked me,

  1. What is NPX and why do we need NPX?
  2. 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

  1. 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

    npx speed-test
    

    image.png
    Reference
    speed-test: An NPM package to check the speed of your internet connection. github

  2. How to check your IP address using NPX?

    npx public-ip-cli
    

    image.png
    Reference
    public-ip-cli : An NPM package to find your public ip address. github

Some of the best package to exercise this workflow

  1. wifi-password-cli: Get current wifi password
    usage:

    npx wifi-password-cli
    

    NPM: npmjs.com/package/wifi-password-cli
    GitHub: github.com/kevva/wifi-password-cli

  2. npkill: Easily find and remove old and heavy node_modules folder
    usage:

    npx npkill
    

    NPM: npmjs.com/package/npkill
    GitHub: github.com/kevva/wifi-password-cli

  3. depcheck: Check your npm module for unused dependencies
    usage:

    npx depcheck
    

    NPM: npmjs.com/package/depcheck
    GitHub: github.com/depcheck/depcheck

Conclusion

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.