考虑有两个文件
./file2.js
function scriptpath()
return __filename
./file1.js
var path = file2.scriptpath()
console.log(path) //returns absolute path of file2.js but not file1.js
我希望从调用文件的位置获得文件(file1.js(的绝对路径。
我想你需要file2.js中file1.js的路径
./file2.js
function scriptpath(callername)
return callername
./file1.js
var path = file2.scriptpath(__filename)
console.log(path) //returns path of file1.js