I'd like to be able to look up the path to a module at build time in node.

I saw in the docs there is `require.resolve` like this

```
// get path to module 'foo'
console.log(require.resolve('foo'));

```

but that looks for path to the entry point of the module. If the module has no entry point (it's just a collection of shared files) then `require.resolve` fails.

I know in some cases I could just look in `node_modules/name-of-module` but in various circumstances that would be wrong. For example I have 'foo' as a dependency and 'foo' as a 'bar' as a dependency. Then by default bar will be in `project-root/node_modules/bar` but if I `npm link` 'foo' then 'bar' will be in `project-root/node_modules/foo(link)/node_modules/bar`

I thought about putting a dummy entry and that works for my own modules but it doesn't work for modules that I don't control.

Is there some way to find the path to the root folder of a given module?

Also is there a way to get the path to a module from the context of some other module.

In other words, normally if I do

```
const bar = require('bar');

```

That's the going to get the 'bar' module referenced in my package.json. Imagine there is some other package 'foo' that includes a different version of 'bar'. I want to be able to ask "what is the path that for 'bar' that package 'foo' would get?"

The actual problem I'm try to solve is to *at build time* copy some files from some module into my build's output folder but to do that I need to be able to find the module.

I can hack something together but it would be nice to do it the "correct" way assuming their is a correct way.