Using a root directory in the NodeJS include

3

I'm learning NodeJS and I started to create a project just to get accustomed to developing with it, however, I'm bothered by the amount of ../../../../../ used to include a code. How can I use the root folder of my application as a path reference?

    
asked by anonymous 29.08.2017 / 21:32

1 answer

3
__dirname

This gives you the path to the currently running file

__filename

This is the absolute path of the current module file

example

console.log(__filename);
// Prints: /Users/mjr/example.js
console.log(__dirname);
// Prints: /Users/mjr
    
29.08.2017 / 21:55