Skip to content

Commit

Permalink
Add Node.js 20.11 import.meta info (#2254)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
casantosmu and sindresorhus committed Jan 14, 2024
1 parent bb9e788 commit eb5af8b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/rules/prefer-module.md
Expand Up @@ -21,7 +21,16 @@ Prefer using the [JavaScript module](https://developer.mozilla.org/en-US/docs/We

They are [not available in JavaScript modules](https://nodejs.org/api/esm.html#esm_no_filename_or_dirname).

Replacements:
Starting with Node.js 20.11, [`import.meta.dirname`](https://nodejs.org/api/esm.html#importmetadirname) and [`import.meta.filename`](https://nodejs.org/api/esm.html#importmetafilename) have been introduced in ES modules, providing identical functionality to `__dirname` and `__filename` in CommonJS (CJS).

For most cases in Node.js 20.11 and later:

```js
const __dirname = import.meta.dirname;
const __filename = import.meta.filename;
```

Replacements for older versions:

```js
import {fileURLToPath} from 'node:url';
Expand Down

0 comments on commit eb5af8b

Please sign in to comment.