Junior
From PDF
Node.js
Node.js
What is the use of __dirname and __filename?
- __dirname: Returns the directory path of the current module.
- __filename: Returns the full file path of the current module.
π Example:
console.log(__dirname); // /Users/yourname/project
console.log(__filename); // /Users/yourname/project/app.js
These are very useful for reading or writing files relative to the script's location.
PM and Module Management
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png