What is npx???😭😭😭

Ah, npx—the Swiss Army knife of the Node.js world. It’s like that one friend who always seems to have exactly what you need at the exact moment you need it.

Included with npm starting from version 5.2.0, npx lets you run Node.js tools like Jest, Mocha, or ESLint without the hassle of installing them globally. Think of it as your on-demand butler for Node.js binaries.


Why Use npx?
1. Avoid Global Installations:
Normally, you’d install tools like Jest or ESLint globally—kind of like turning your whole house into a storage unit just to store a single wrench. But with npx, you don’t have to clutter your global space! It’ll run the local version of a tool (if it’s already in your project) or temporarily download it for you faster than you can say, “npm who?”

2. Execute Local Project Tools:
When you install Jest locally (npm install jest --save-dev), it takes up residence in your node_modules folder like a polite houseguest. npx ensures it uses this local version instead of waking up a global one and risking, “Wait, why is this behaving differently here?” vibes.

3. One-Time Use:
Need a tool but don’t want to commit to it like it’s a long-term relationship? Just use npx! For instance:

npx create-react-app my-app

It downloads, uses, and then lets go—like the perfect fling.


How npx Works with Jest
If you’ve installed Jest locally with:

npm install jest --save-dev

You can run:

npx jest

Boom! Local Jest at your service. If you haven’t installed it, npx will fetch it for you, like DoorDash for dev tools.


Key Differences: npm vs npx

Featurenpmnpx
Installing ToolsInstalls globally or locally.Skips installation; runs directly.
Running ToolsNeeds npm run for local tools (ugh).Directly runs tools like a boss.
FlexibilityOnly works with installed tools.Runs anything, installed or not.

Examples of Using npx

  • Run Jest:

      npx jest
    

    It’s like, “Who needs commitment? Just run the tests.”

  • Run ESLint:

      npx eslint yourFile.js
    

    Because clean code is a lifestyle, not a suggestion.

  • Create a React App:

      npx create-react-app my-app
    

    Skip the awkward global install phase. Just spin up your app and go!


Why Is Everyone Obsessed with npx?
Developers these days are all about keeping things lightweight and avoiding unnecessary global installs—like Marie Kondo but for dev environments. Tools are usually installed per project, and npx ensures you’re always using the correct local version. It’s simple, it’s fast, and it’s here to keep your dev life drama-free.

So, next time you see a bunch of npx commands, just think of it as the Uber of Node.js tools: always available, always reliable, and never overstaying its welcome.

0
Subscribe to my newsletter

Read articles from Maneeshwar Karne directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Maneeshwar Karne
Maneeshwar Karne

Learning web devlelopment