what's an ideal way to get path of a caller file

i've found the method that works for me, but it's too hacky to be true lmao
function() {
let callerPath = new Error().stack!.split("\n")[2]!;
for (let i = 2; i > 0; i--) {
callerPath = callerPath.slice(
callerPath.lastIndexOf("("),
callerPath.lastIndexOf(":")
);
}
return callerPath.slice(1, callerPath.length);
}
function() {
let callerPath = new Error().stack!.split("\n")[2]!;
for (let i = 2; i > 0; i--) {
callerPath = callerPath.slice(
callerPath.lastIndexOf("("),
callerPath.lastIndexOf(":")
);
}
return callerPath.slice(1, callerPath.length);
}
so i'm asking, is there no better way to do the same thing?
Solution:
whatever, i use process.cwd()
Jump to solution
2 Replies
Solution
🐀
🐀2mo ago
whatever, i use process.cwd()
🐀
🐀OP2mo ago
nah, this idea can be evolved and improved. but i've found flaws already, and thank you i don't have to be that dependent on a stack

Did you find this page helpful?