VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-__dirname-variable/

⇱ Node.js __dirname Variable - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js __dirname Variable

Last Updated : 8 Apr, 2021

The __dirname string gives the directory path of the current module, this is also similar to that of path.dirname() of the filename.

Return Value : It returns the directory path of the current module.

Example 1: Let's create a file main.js

Output: Now run node main.js.

👁 Image

Example 2: Replicating __dirname with path.dirname().

Output: Now run node main.js.

👁 Image
Reference:https://nodejs.org/docs/latest/api/globals.html#globals_dirname
Comment
Article Tags:

Explore