In this article, we will learn the difference between npm vs npx of Node.js.
npm
npx
- Node Package Manager.
-
Node
Package
Execute.
(Also known as Node Package Runner.)
-
Installed with Node.js.
[ https://nodejs.org/en/download ]
-
Installed with npm.(npm above 5.2.0 version)
[ npm install -g npx ]
-
It is World’s largest software registry.
(https://www.npmjs.com)
And also includes a CLI tool named as npm.
- It is a CLI tool named as npx.
- Use to install/Manage packages.
- Use to eXecute packages.
-
To use a package, need to install it from the npm registry into the system.
[ Command to install locally: npm install]
[ Command to install globally: npm install -g]
-
No need to install a package into the system.
(Directly use a package from the npm registry)
[ Command to execute directly: npx your-package-name ]
- It will look for package installed locally or globally in your machine.
- If a package is installed locally or globally in your machine, it will use that else it will take directly from npm registry.
- It Increases the node_modules size if we do not need the installed package (incase of testing purpose).
- It helps reducing the node_modules size if we do not need the installed package (incase of testing purpose).
-
Use package in two ways:
1. Using the package’s installed path.
Command: ./node_modules/.bin/your-package
2. Using package.json
Add package name under ‘scripts’ section.
{
“name”: “your-application”,
“version”: “1.0.0”,
“scripts”: {
“test-package”: “your-package”
}
}
And then execute the package using below command:
[ npm run test-package ]
-
Directly execute the package using below command:
[ npx your-package-name ]
I hope this helps you understand the difference between npm vs npx side by side.
References
- https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm
- https://loadfocus.com/blog/react/2019/04/how-to-use-npx-the-npm-package-runner
- https://www.xspdf.com/resolution/50605219.html
- https://www.educative.io/edpresso/what-is-npx
Related Posts
Visit https://techtalkbook.com to find more related topics.
Happy Coding!!!