I have a nodejs app that requires a node module "A" that's available locally on my machine in ./node_modules
. Can I require("A")
in my app.js without specifying that "A" exists in package.json
, yarn.lock
, or package-lock.json
?
the package-lock.json
and yarn.lock
are modified each time you add or remove a dependency from your application. in more simpler ways whenever you use npm
or yarn
they just modify these lock files respectively.
the only file that you can edit in package.json
both the package managers take this file as input, detect all the packages listed inside them and then install them (including further dependencies of each). Now coming back to your question, Yes you can add a folder to node_modules without mentioning it in package.json
and the require
will work the same as you want but there are some drawbacks, such as whenever you use npm or yarn afterwards they will remove the folder/file from the node_modules because it has not been mentioned in package.json
. moreover in case of building project, only the files mentioned in package.json
are bundled with the build so, your files might not get bundled.