Node Package Manager, or npm, is a central repository for JavaScript open-source development tools. Developers worldwide use it to download and share reusable code packages, manage project dependencies, and more. This article provides a comprehensive guide on how to check the versions of npm packages installed on your machine.
Checking the version of npm itself
Before proceeding to check the npm package versions, it’s essential to know which version of npm itself you’re running. The following command will help you accomplish that:
npm -v
Executing this command will display the version of npm installed on your system.
Checking the version of globally installed packages
Global npm packages are installed system-wide and can be accessed from anywhere on your computer. To check the version of a globally installed package, use the following command:
npm list -g --depth=0
The -g flag means “global”, and --depth=0
prevents the command from listing sub-dependencies of the global packages. This command will provide a list of all globally installed packages, along with their respective versions.
Checking the version of a specific globally installed package
If you want to check the version of a specific globally installed package, you can use the following command:
npm list -g --depth=0 <package-name>
Replace <package-name> with the name of the package you’re interested in. This command will output the package name and its version if it’s installed globally.
Checking the version of locally installed packages
Local npm packages are those installed in your project directory and are accessible only within that directory. To see a list of all local packages and their versions, navigate to your project directory and run:
npm list --depth=0
This will provide a list of all locally installed packages (dependencies specified in your package.json file), along with their versions.
Checking the version of a specific locally installed package
To find the version of a specific locally installed package, use the following command:
npm list <package-name>
Again, replace <package-name> with the name of the package you’re interested in. This command will show the version of the package installed in your local project.
Understanding Semantic Versioning
When you check the versions of npm packages, you’ll likely see numbers in a format like this: 1.0.2. This is known as semantic versioning. The three numbers correspond to major.minor.patch.
- The major number changes when there are incompatible changes in the API.
- The minor number changes when functionality is added in a backwards-compatible manner.
- The patch number changes when backwards-compatible bug fixes are made.
This system helps developers understand the impact of upgrading a package on their projects.
Conclusion
In conclusion, checking the version of your npm packages is a vital part of maintaining and debugging your JavaScript projects. Regularly updating your packages helps you take advantage of the latest features and security updates. But, always remember to thoroughly test your project after updating, to ensure everything still works as expected.