Underscore Underscore gives you magic variables to figure out what file (or line or column) you are in, get a stack trace, or know what code called the current file. Sometimes you just need node's __file magic variable or console.trace() function.

npm install underscoreunderscore
2 downloads in the last week
8 downloads in the last month


There are other approaches to this in node by using the __file global variable and the console.trace() function. For getting true cross-browser functionality, you might want something like this: https://github.com/eriwen/javascript-stacktrace

Across browsers and node however, this is how you get a stack trace

function(){{ try { throw Error(''); } catch(err) { return err; } }; };

That'll give you a stack trace (as a string), but for just the relevant data, __ comes to the rescue.


npm install -g underscoreunderscore
var __ = require("underscoreunderscore");

Getting Info

You can get files like this:


You can get the whole stack trace like this:


You can get the whole file (+line and column numbers) like this:


Lastly, you can grab the filename that executed code before like this:

var callingFile  = __.caller;
npm loves you