Finding the location of a file that calls a function (nodejs)
问题 If a method of a module is called from within a file, can I tell the location of that file from within the module? So // my-module.js module.exports = { method: function () { // in here I would like to detect the path to my-app.js } } // my-other-module.js require('my-module').method(); I want some equivalent of access to __filename for my-other-module.js from within my-module.js. I don't want to have to pass __filename as a parameter 回答1: For a utility logging you could use this (I used