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

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content onlyβ€”not admin or internal tools.

care@toolliyo.com

Need callback? Share your details