es module __dirname alternative

JavaScript
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

Source

Also in JavaScript: