In Node.js, different packages are installed. But, of course, to manage all of them, you need something. That’s where npm comes in. Npm (node package manager) manages all the packages. In other words, it is a tool that is used to install packages. Further, it puts modules in place that Node.js can locate. It also manages dependency conflicts.
This means you only need to specify your project dependencies in the package.json file. If you need to install the dependencies, you just need to run npm install
. It is also the dependency manager you get whenever you install Node.js. With the help of npm, developers can install packages.
But how do you install packages using npm?
Write the following:
npm install {your-package}
Check whether your package is installed by looking under ‘dependencies’ in the package.json file.
Just one piece of advice: Choose which npm packages you use wisely. They are developing quickly. In fact, always prefer to use npm packages that are not only the most stable and popular but also not retiring in the near future.
Npx or Node Package eXecute, on the other hand, is an NPM package runner that helps developers execute any package available on the NPM registry. It also deletes and updates JavaScript packages without the need to install them. It assists in making npm simpler as well as more powerful.
Moreover, for developers, in case they are using something that is heavily reliant on node.js when deploying to the cloud, it is often recommended to master npx.
What’s even better?
Thanks to npx, you can execute packages from the npm registry without needing to install them. Particularly, npx is useful for one-time use packages. Moreover, by default, npx first checks if the package that needs to be executed is present in the path or not. If the package isn’t installed, then npx will install it automatically. Otherwise, it will be executed directly. In other words, npx is a tool used to execute packages.
But here’s the catch: if you have installed npm version under 5.2.0, you will need to install npx on your system because npx isn’t included in those versions.
Don’t know whether npx is installed on your system? Write the following:
npx — v
Install it in your system by writing:
npm install -g npx
So what actually is npx? Well, it is a CLI tool that makes it hassle-free for you to install and manage dependencies. By downloading it, you can also run it in the local directory. What other benefits does npx offer? Well, you can create a React app without ensuring that all the packages are installed. Just write:
npx create-react-app my-app
Here, all the necessary files essential to run the package create-react-app will be downloaded. The files will be executed in the parameter my-app. This means our app will be created and initialized in the my-app folder.
Top comments (0)