is it possible to have a global function that gets the file name of the file it is currently executed in? As an example, let's say i have it defined in abc.js, and when i run it in def.js, it returns "def.js", when i run it in "somefile.js" it returns "somefile.js" etc.
Asked
Active
Viewed 19 times
0
-
does this help? https://stackoverflow.com/questions/710957/how-might-i-get-the-script-filename-from-within-that-script or this: https://stackoverflow.com/questions/13829037/how-to-get-filename-of-script-being-executed-in-nodejs – J_K Sep 01 '21 at 12:37
-
Does this answer your question? [How to get the file-path of the currently executing javascript code](https://stackoverflow.com/questions/2255689/how-to-get-the-file-path-of-the-currently-executing-javascript-code) – Heretic Monkey Sep 01 '21 at 12:38
-
The answer depends on the host environment really, not to mention a number of other variables. For instance, in the context of modules, if the code being executed is imported from another file, do you want the name of the imported file or the name of the file it was imported into? Or the file that kicked off the execution context in the beginning? – Heretic Monkey Sep 01 '21 at 12:42
-
the file that kicked off the execution context, yes – Fr3d Fields Sep 01 '21 at 12:49