How can one get the name and line of a function that called the current one? I would like to have a rudimentary debugging function like this (with npmlog defining log.
I found and installed the node-stack-trace module (installed with npm install stack-trace
), and then defined echo
as:
function echo() {
var args, file, frame, line, method;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
frame = stackTrace.get()[1];
file = path.basename(frame.getFileName());
line = frame.getLineNumber();
method = frame.getFunctionName();
args.unshift("" + file + ":" + line + " in " + method + "()");
return log.info.apply(log, args); // changed 'debug' to canonical npmlog 'info'
};