How to make local library available as a installed module on Node.js

387 Views Asked by At

Have a look at Dredd, for example, it makes the library Hooks available when you are running a script with the dreddcommand.

Command line

$ dredd [...] --hookfiles=./hooks.js

hooks.js

const hooks = require('hooks');
...

How does it work?

2

There are 2 best solutions below

0
On

Check out npm link, which can be used to "link" together local modules as if they were a dependency visible in the node_modules directory. This can be very useful when splitting off code into a library. I'm not exactly sure what dredd is doing, but it is likely based off of the npm link paradigm.

0
On

I'm the maintainer of Dredd. In Dredd's case it's implemented using the proxyquire library. I think rewire does similar things.