0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

doc: add example on how to create __filename, __dirname for esm

PR-URL: https://github.com/nodejs/node/pull/28282
Fixes: https://github.com/nodejs/node/issues/28114
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Walle Cyril 2019-06-19 01:21:23 +02:00 committed by Luigi Pinca
parent cf929c04b0
commit 84ad92d2e7

View File

@ -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 <code>require.extensions</code>