Node.js Global Objects: __dirname and __filename
Global objects in Node.js are available in all modules without the need to require() them. Two important ones are __dirname and __filename.
__dirnameDefinition: The absolute path of the directory containing the currently executing file.
Usage Example:
console.log(__dirname);
Output Example:
C:\Users\YourName\Projects\myapp
This is helpful for reading or writing files relative to the current script.
__filenameDefinition: The absolute path of the currently executing file itself (including the file name).
Usage Example:
console.log(__filename);
Output Example:
C:\Users\YourName\Projects\myapp\index.js
This is useful when you need to reference the file path directly.


