Get directory name and filename of the current module in Nodejs
We can use the variables __dirname and __filename to get the directory and filename respectively. These variables appear global, but they are not. Read more about them here.
__dirname
Example: running node example.js from /Users/mjr
console.log(__dirname);// Prints: /Users/mjrconsole.log(path.dirname(__filename));// Prints: /Users/mjr__filename
console.log(__filename);// Prints: /Users/mjr/example.jsconsole.log(__dirname);// Prints: /Users/mjr