Node_modules dependencies vs. package.json file

Hi,

If I delete my node_modules folder, which contains dependencies needed by specific dependencies stored in my package.json file, how are my dependencies saved inside my package.json still able to work?

Are the node_modules dependencies saved somewhere else, like package.json-lock?

BTW, what exactly is package.json-lock? Thanks!

The lock file (yarn or npm) is a “housekeeping” file, auto-generated by the package manager as you make changes to your project, or when you run yarn install or npm install.

Normally, when you delete the node_modules folder, they folder and its contents are gone. You then run the package manager install command to regenerate the node_modules folder (and its contents) based on the project package.json contents.

I realize this isn’t an answer to what you experienced – not sure how your project still compiled and ran after deleting the node_modules folder.