Node.js - getting current filename


Question

How to get current file name, function name and line number?

I want to use it for logging/debugging purpose, equivalent to __FILE__, __LINE__ in c

1
96
1/7/2013 6:04:11 PM

Node.js provides a standard API to do so: Path.

Getting the name of the current script is then easy:

var path = require('path');
var scriptName = path.basename(__filename);
203
3/6/2015 4:27:10 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon