In this article, we will learn the difference between npm vs npx of Node.js.
- Node Package Manager.
(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.
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.
2. Using package.json
Add package name under ‘scripts’ section.
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.
Visit https://techtalkbook.com to find more related topics.