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?

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);