Nodejs: get filename of caller function

前端 未结 7 1240
心在旅途
心在旅途 2020-11-30 03:41

I wonder how-to get an absolute path of a caller of a function?

Let say that:

in file a.js I call b(); b() is a functi

7条回答
  •  忘掉有多难
    2020-11-30 04:01

    You can use require.resolve(module) to determine the full path of a module:

    var path = require.resolve("a");
    
    //or
    
    var path = require.resolve("./a.js");
    

提交回复
热议问题