How to get filename of script being executed in NodeJS?

How to get filename of script being executed in NodeJS application?

You can use variable __filename

http://nodejs.org/docs/latest/api/globals.html#globals_filename

You need to use process.argv. In there will be the name of the script that was executed from the command line, which can be different than what you will find in __filename. Which is appropriate depends on your needs.

http://nodejs.org/docs/latest/api/process.html#process_process_argv

Use the basename method of the path module:

var path = require('path');
var filename = path.basename(__filename);
console.log(filename);

Here is the documentation the above example is taken from.