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 <myles.borins@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
  • Loading branch information
GeoffreyBooth authored and targos committed Dec 1, 2019
1 parent 47fa164 commit 9d6c293
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 @@ -540,16 +540,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 9d6c293

Please sign in to comment.