Skip to content

Instantly share code, notes, and snippets.

@capaj
Last active February 9, 2017 12:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save capaj/a9ba9d313b79f1dcd9a2 to your computer and use it in GitHub Desktop.
Save capaj/a9ba9d313b79f1dcd9a2 to your computer and use it in GitHub Desktop.
showcase of module.parent
var myFunc = require("./myFunc");
(function bar(){
myFunc("bar message");
})();
var myFunc = require("./myFunc");
(function foo(){
myFunc("foo message");
})();
function myFunc(arg){
console.log(arg);
console.log(module.parent.filename);
// Here I need the file path of the caller function
// For example, "/path/to/foo.js" and "/path/to/bar.js"
}
module.exports = myFunc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment