Replacement for __dirname and __filename when using Modules
over CommonJS
import {fileURLToPath} from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
However, in most cases, this is better:
import {fileURLToPath} from 'url';
const foo = fileURLToPath(new URL('foo.js', import.meta.url));
And many Node.js APIs accept URL directly, so you can just do this:
const foo = new URL('foo.js', import.meta.url);
Cut from: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v38.0.0/docs/rules/prefer-module.md