DEV Community

Cover image for NPM v/s NPX
Anuradha Aggarwal
Anuradha Aggarwal

Posted on • Originally published at anuradha.hashnode.dev

NPM v/s NPX

Hello Developers!! While working on any of your projects you might have come across NPM.

NPM stands for Node Package Manager and is a go to tool for managing NodeJS packages.

  • It helps you install libraries, manage dependencies & even define scripts to automate tasks.

Now switch to the term NPX which stands for Node Package Execute

  • it comes with the NPM, when you installed NPM above 5.2.0 version then automatically NPX will installed.

  • It is a NPM package runner that can execute any package that you want from the NPM registry without even installing that package.

Let’s take a simple example to understand the difference between the two:

🎯 NPM

📍 Example

Create a new directory

mkdir test-project
cd test-project
Enter fullscreen mode Exit fullscreen mode

Now install the package cowsay using NPM

npm install cowsay
Enter fullscreen mode Exit fullscreen mode

NPM command example

Now if you check your project directory there will be new entry created inside the node_modules

Project directory

You can use this new package using that path like

./node_modules/.bin/cowsay hello
Enter fullscreen mode Exit fullscreen mode

command cli

Or instead of using the whole path, directly use the package name like

cowsay world
Enter fullscreen mode Exit fullscreen mode

cli command

So now you understand whenever we use NPM for any package update you have to install it which will occupy space in your system.

📍 Usage

  • You are working on a long-term project where you’ll frequently use the same packages and libraries.

  • You want to manage dependencies and ensure they are tracked in your package.json.

🎯 NPX

📍 Example

It is a NPM Package Executor that can execute any package that you want from the NPM registry without even installing that package.

Let’s try this out:

mkdir test-npx
cd test-npx

npx cowsay hello
Enter fullscreen mode Exit fullscreen mode

npx command

Also if you check test-npx directory, it is empty that means this package does not occupy any space.

npx example directory

📍 Usage

  • You want to execute a package without permanently installing it.

  • You’re running one-off commands like create-react-app, eslint, or package binaries.

  • You need to run a specific version of a package or command without modifying your existing setup.

🎯 Wrap Up!!

That's all for this article. Thank you for your time!! Let's connect to learn and grow together. LinkedIn Twitter Instagram

Top comments (0)