Skip to content

Commit

Permalink
doc: createRequire can take import.meta.url directly
Browse files Browse the repository at this point in the history
PR-URL: #30495
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
  • Loading branch information
GeoffreyBooth authored and MylesBorins committed Nov 16, 2019
1 parent f61882b commit 79126fc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,15 @@ CommonJS, JSON, and Native modules can be used with
[`module.createRequire()`][].

```js
// cjs.js
// cjs.cjs
module.exports = 'cjs';
// esm.mjs
import { createRequire } from 'module';
import { fileURLToPath as fromURL } from 'url';
const require = createRequire(fromURL(import.meta.url));
const require = createRequire(import.meta.url);
const cjs = require('./cjs');
const cjs = require('./cjs.cjs');
cjs === 'cjs'; // true
```

Expand Down

0 comments on commit 79126fc

Please sign in to comment.