Skip to content
the poor coder

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

Poor Man
Published
Reading time
2 min read
On this page

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:

Bash
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:

Bash
npm install lodash@1.2.3

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:

JSON

"dependencies": {
  "lodash": {
    "version": "1.2.3",
    "resolved": "https://registry.npmjs.org/lodash/-/lodash-1.2.3.tgz",
    "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.

Conclusion#

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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC