Skip to content

Commit

Permalink
doc: add example on how to create __filename, __dirname for esm
Browse files Browse the repository at this point in the history
PR-URL: #28282
Fixes: #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>
  • Loading branch information
GrosSacASac authored and targos committed Jul 20, 2019
1 parent d34c256 commit d7c7023
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d7c7023

Please sign in to comment.