![]() |
VOOZH | about |
package-lock.json is a file that is generated when we try to install the node. It is generated by the Node PackageManager(npm). package-lock.json will ensure that the same versions of packages are installed.
It contains the name, dependencies, and locked version of the project. It will check that same versions are installed for the different users so that errors can be prevented (Dependency locking).
Table of Content
Step 1: Check the version of node and npm to verify that it is installed in our system.
node -v
npm -v
The above command will display the version of the node installed.
Step 2: Now open Visual Studio Code. Click on Create New File and name it with .js extension. ( Example: index.js) .
Within that, open the terminal/command line and execute the below command.
npm init -y
Step 3: Install the required dependencies for the project.
npm i express
The common method of starting a package is npm init. After doing this, a package.json file is created. But when we install a express, we can notice the package-lock.json file (usually very long) gets automatically created.
Output: The output will be the package-lock.json file with a long descriptions. Since we are installing express , the package-lock.json will show the dependencies of express.
👁 Screenshot-from-2024-03-04-21-10-10-(1)-min-(1)-(1)
From the above output image consider first few lines . Let's describe some of them.
package.json | package-lock.json |
|---|---|
It displays the basic information about the project | It describe a exact tree structures that allow to download identical trees |
It is required for every project. | It is automatically generated when installing node modules |
It contains information such as name, description, author, script, and dependencies. | It contains the name, dependencies, and locked version of the project. |