Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Created May 4, 2012 22:55
Show Gist options
  • Save tjanczuk/2598211 to your computer and use it in GitHub Desktop.
Save tjanczuk/2598211 to your computer and use it in GitHub Desktop.
iisnode interceptor
(function () {
// refactor process.argv to determine the app entry point and remove the interceptor
var appFile;
var newArgs = [];
process.argv.forEach(function (item, index) {
if (index === 2)
appFile = item;
if (index !== 1)
newArgs.push(item);
});
process.argv = newArgs;
// intercept console.log to convert strings to uppercase
var oldLog = console.log;
console.log = function (thing) {
if (typeof thing === 'string')
oldLog(thing.toUpperCase());
else
oldLog.apply(this, arguments);
};
// run the original application entry point
require(appFile);
})();
nodeProcessCommandLine: "c:\program files (x86)\nodejs\node.exe" "c:\program files\iisnode\www\helloworld\interceptor.js"
@williamkapke
Copy link

The interceptor should overwrite require.main.filename to point to the one that is expected. It is used to figure out what module kicked off a process. In a web app, it is often used to find the root of the website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment