Skip to content

Instantly share code, notes, and snippets.

@matt-
Created February 14, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-/260d383b936a342d3dab84b574b9db18 to your computer and use it in GitHub Desktop.
Save matt-/260d383b936a342d3dab84b574b9db18 to your computer and use it in GitHub Desktop.
NativeModule
var Module = require('module');
var old_wrap_zero = Module.wrapper[0];
// some code to inject into a module load.
var code = '\n(' + (function (){
process.NativeModule = require('native_module');
}) + ')();\n';
Module.wrapper[0] += code;
// http is lazy loaded
var http = require('http');
// reset module wrpper
Module.wrapper[0] = old_wrap_zero;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment