How to generate package-lock.json in nodejs forcebly with npm

forceble generate package-lock.json example

package-lock.json files are generated automatically while running npm install or npm update.

It also generates any changes to the recursive node_modules folder tree.

Sometimes, the developer deletes this or only wants to update this file.

This post shows you many ways to generate or update the package-lock.json file in NodeJS.

However, this can be disabled in the .npmrc settings file with package-lock=false.

Please check the home directory .npmrc file for package-lock settings.

It is a global node configuration that applies to running OS.


if package-lock is false, It won’t generate package-lock.json. by setting package-lock.json file, It generates package-lock.json file automatically on npm install command.

You can also run changing this with command line

npm config set package-lock true

package-lock.json is introduced from NodeJS version 5. x and It contains all direct and indirect dependencies of a node application.

First, run the npm install command.

npm install

It generates a package-lock.json file in the node directory.

Sometimes, You want to generate a package-lock.json file without npm install. How to do it?

How to update package-lock.json without doing npm install?

Run below command

npm install --package-lock-only

It updates the package-lock.json file without downloading package dependencies.

It works only since node 5. x version.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.