I use the flag --experimental-modules when running my node application in order to use ES6 modules.
--experimental-modules
However when I use this flag the metavariable
import path from 'path'; const __dirname = path.join(path.dirname(decodeURI(new URL(import.meta.url).pathname))).replace(/^\\([A-Z]:\\)/, "$1");
This code also works on Windows. (the replacement is safe on other platforms, since path.join returns back-slash separators only on Windows)
path.join