Y
Y
Yustas Alexu2015-05-27 19:38:37
Node.js
Yustas Alexu, 2015-05-27 19:38:37

How to get the root directory from a module?

In general, this directory structure is:
/app.js
/lib/View.js
/views/index.html
View.js reads index.html in the views folder. As you know, __dirname is different for each module. So I pass __dirname from app.js to the View.js instance to get the root directory there. It doesn't turn out very pretty. How else can I get the root directory of the main script from within any module?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
copal, 2015-05-27
@Yuxus

Perhaps you are talking about this?
global.process.cwd();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question