Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If I understand correctly, you need a path to the application file? Let's say you run the application /var/www/mysuperapp/app.js and you need to get the path to this file.
if so, then the __dirname variable is what you need. this variable is available within each file, and contains the path to the file within which it is used.
if you have one file nested in another, require is used and you need to know the root of the application (main file) everywhere, then the easiest option is to write the path of the main file to a global variable and use it in nested files
/* файл /var/www/mysuperapp.js */
global.__approot = __dirname;
require('./requires/child.js');
/* файл /var/www/requires/child.js */
console.log(__approot); // /var/www/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question