how to install exact package lock version in package-lock.json

How to Install Exact Package Lock Version in package-lock.json?

If you have worked with Node.js projects, you may have come across the package-lock.json file. This file is generated automatically by npm to keep track of the exact versions of dependencies installed in your project. However, sometimes you may need to install a specific version of a dependency mentioned in this file. In this article, we will discuss how to install an exact package lock version in package-lock.json.

Option 1: Using npm install

The easiest way to install a specific version of a package is by using the npm install command. You can specify the package name and version number in the command as follows:

npm install package-name@version-number

For example, if you want to install version 1.2.3 of the lodash package, you can run the following command:

npm install [email protected]

This will update the package-lock.json file with the exact version number you have installed. If the package is not available in the specified version, npm will throw an error.

Option 2: Updating package-lock.json directly

If you want to update the package-lock.json file directly, you can do so by manually changing the version number of the dependency you want to update. You can open the file in a text editor and find the dependency section you want to update. Here's an example:

"dependencies": {
  "lodash": {
    "version": "1.2.3",
    "resolved": "",
    "integrity": "sha1-9/1c7/2NjGW9+2/5algQFbKHmVc="

You can update the version number in the "version" field and save the file. After that, you can run the npm install command to install the exact version you just updated.


These are the two options you have to install an exact package lock version in package-lock.json. The first option is easier and recommended, as it is less prone to errors. However, if you need more control over the package-lock.json file, you can use the second option.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]