NPM is a default package manager for Node.js. NPM manages all the internal as well as external packages or modules that we use in various node.js applications. Default Packages in NPM cannot fulfill the needs of the developer, so we need external packages, and we can install either locally in a particular directory on our machine or globally that are easily accessible in any location on our machine.
Installing npm package locally using the below command: This command will install the mentioned package in our local directory.
npm install <package-name>
Installing npm package globally using the below command: This command will install the mentioned package globally. Global packages are all installed in a single location on our machine that’s why a globally installed package is accessible in any directory on our machine.
npm install -g <package-name>
Methods to check the installed version of Node.js. packages on our machine:
Checking locally installed Node.js packages in a particular directory using the below command.
Checking globally installed packages on our machine using the below command.
npm list -g
Checking specific package globally installed node.js package using below command.
npm ls -g <package_name>
Checking Local top-level domain of packages only and not all sub-packages using the below command.
npm list --depth=0
Checking Globally Top-level domain node.js packages using the below command.
npm list --depth=0 -g
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.