Is there any way for node.js to know the actual path of the module referenced by the lock?

for example, a koa package is referenced in Node.js:

const Koa = require("koa")

because Node.js automatically looks in the node_modules of the current directory when it loads a package without a path. If you can"t find it, you"ll look for it at the top. With this flat structure, it"s not easy for me to know which layer Node loaded the package from.

is there any way to print the path of the current package load in the code?

Apr.07,2021

require.resolve () ,
read more documents

Menu