SyntaxStudy
Sign Up
Home Node.js Reference __dirname / __filename

__dirname / __filename

property

__dirname is the directory of the current module; __filename is its full path. Not available in ES modules.

Syntax

__dirname __filename

Example

javascript
console.log(__dirname);   // /home/user/project/src
console.log(__filename);  // /home/user/project/src/app.js

// Build absolute paths
const path = require('path');
const configPath = path.join(__dirname, '..', 'config.json');
const uploadDir  = path.join(__dirname, 'uploads');