Skip to content

Instantly share code, notes, and snippets.

@ashleydavis
Last active September 22, 2019 09:16
Show Gist options
  • Save ashleydavis/0f4ccd40a8253e3dd2641e03a5300376 to your computer and use it in GitHub Desktop.
Save ashleydavis/0f4ccd40a8253e3dd2641e03a5300376 to your computer and use it in GitHub Desktop.
This snippet of code sets up a hook to intercept calls to require in Node.js. Put this code at the entry point of your app. It's a great debugging tool for Node.js and it even works under Electron!
//
// Original code here.
//
// https://stackoverflow.com/a/41674522/25868
//
const m = require('module');
const originalLoader = m._load;
m._load = function(request, parent, isMain) {
console.log(`## ${request} from ${parent.id} at`);
console.trace();
return originalLoader(request, parent, isMain);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment