node-hook

Run source transform function on Node require

npm install node-hook
1 downloads in the last day
12 downloads in the last week
15 downloads in the last month

node-hook

Run source transform function on Node require

NPM

Build status dependencies devdependencies

endorse

Install and use

npm install --save node-hook

Before loading desired .js files, install hook

require('node-hook');

function logLoadedFilename(source, filename) {
    return 'console.log(' + filename + ');\n' + source;
}
hook.hook('.js', logLoadedFilename);
require('./dummy');
// prints fulle dummy.js filename, runs dummy.js

hook.unhook('.js'); // removes your own transform

remember: Nodejs caches compiled modules, so if the transform is not working, you might need to delete the cached entry in require.cache, then call require(filename) again to force reload.

Small print

Author: Gleb Bahmutov © 2013

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

npm loves you