polkovnikov.ph
polkovnikov.ph

Reputation: 6632

Node.js: How to substitute one library with another?

There's a library memoize-fs that uses fs package inside. There's a drop-in replacement for fs called graceful-fs that is a must have when working with a lot of files simulatneously. I'd like to trick memoize-fs into using graceful-fs without fixing its source code (this approach is obvious). How do I do it?

Upvotes: 2

Views: 178

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 145994

I would look into using rewire for this.

var rewire = require('rewire');
var memoizefs = require('memoize-fs');
var gracefulfs = rewire('graceful-fs');
gracefulfs.__set__('fs', memoizefs);

Upvotes: 1

Related Questions