require-patch
Patch the global nodejs require hook
Installation
npm install require-patch
Usage
Let's say you want to setup a function that copies files when they're required, you might want to use it like this
usage.js
var copied = require.copy('./myjsonfile.json');
Here's how you'd set that up in your main app file
main.js
extend = require('extend');var patcher = require('require-patch'); patcher.patch(function(globalRequire) { globalRequire.copy = function(filepath) { return extend(true, {}, globalRequire(filepath)); }}); usage = require('./usage');