Skip to content

Instantly share code, notes, and snippets.

@carlotrimarchi
carlotrimarchi / server.js
Last active April 19, 2024 08:18
__dirname and absolute path in Node v20, with ESM
import path from 'path';
import { fileURLToPath } from 'url';
// get the path of the current file
const __filename = fileURLToPath(import.meta.url);
// get the current directory
const __dirname = path.dirname(__filename);
const absolutePath = __dirname + "/" + "somePicture.jpg";
console.log(absolutePath)