Victor Ferreira
Victor Ferreira

Reputation: 6449

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

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?

Upvotes: 1

Views: 417

Answers (2)

Honza Javorek
Honza Javorek

Reputation: 8796

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

Upvotes: 1

jakemingolla
jakemingolla

Reputation: 1639

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.

Upvotes: 0

Related Questions