Get current and root path and containing folders of files in Node.js application

Get current and root absolute path and containing folders of files in Node.js application

1 Get current File and Folder path in Node.js

const fs = require('fs');
exports.details = function(req, res){

	//Get the current file path
	console.log(__filename);

	//Get the current folder
	console.log(__dirname);

	//returning response
	...

};

2 Get project ROOT File and Folder path of server.js in Node.js

const fs = require('fs');
exports.details = function(req, res){

	//Get the current file path
	console.log(require.main.filename);

	//Get the current folder
	  console.log(path.dirname(require.main.filename));

	//returning response
	...

};