Comments

The nodejs local module path trick

Sometimes you have a module installed locally that happens to have the same name as a core module. As an example you may have a module called util.

Now if you var util = require('util') you actually get the node core util module, not what you wanted right?

So then you may think var util = require('./node_modules/util') maybe the end all be all.

Not so fast scotty! Cuz if someone installs your library as a dependency and runs npm dedupe then your util module may get moved up one or more directories, well and then it's not where you are trying to find it anymore.

There is however a nice little trick I found today in one of @defunctzombie's modules

Asking for the util module via var util = require('util/') (trailing slash is important) will make nodejs load it from your local node_modules, but also find it if it was moved due to npm dedupe.

And that's all there is too it.