Y
Y
Yuri Puzynya2014-12-04 22:08:24
JavaScript
Yuri Puzynya, 2014-12-04 22:08:24

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/appin the variable . process.mainModule.filenameBut 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

2 answer(s)
T
Timur Shemsedinov, 2014-12-05
@MarcusAurelius

console.dir(process.argv);
console.log(process.argv[1]);
console.log(__filename);

L
Lynn "Coffee Man", 2014-12-09
@Lynn

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 question

Ask a Question

731 491 924 answers to any question