Answer the question
In order to leave comments, you need to log in
What is the most convenient way to get the real name of a file?
If the process is started in Windows as , then this line will be node folder/app
in the variable . process.mainModule.filename
But now let's assume that the real name of the file App.js
, i.e. in this case, the difference in register is important to me. Of course, there are many ways to get this name, but it seems to me that there definitely must be a way in one or two lines of code, which I am missing.
Can you suggest me one like this? Code examples are not required, just an algorithm or a link.
Answer the question
In order to leave comments, you need to log in
console.dir(process.argv);
console.log(process.argv[1]);
console.log(__filename);
console.log(require.resolve(process.argv[1]));
nodejs.org/api/globals.html#globals_require_resolve
or even:
nodejs.org/api/modules.html#modules_accessing_the_...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question