diff --git a/doc/api/esm.md b/doc/api/esm.md index c4edc523571336..8b7b632f1cdad7 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -278,7 +278,16 @@ These CommonJS variables are not available in ES modules. `require` can be imported into an ES module using [`module.createRequire()`][]. -An equivalent for `__filename` and `__dirname` is [`import.meta.url`][]. +An equivalent for variable `__filename` and `__dirname` can be created inside +each file with [`import.meta.url`][]. + +```js +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +``` ### No require.extensions