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 MylesBorins committed Nov 17, 2019
1 parent d37d340 commit 7e603be
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 7e603be

Please sign in to comment.