Skip to content

Commit

Permalink
doc: improve createRequire() example
Browse files Browse the repository at this point in the history
Update the example to use import and import.meta.url instead
of require() and require.resolve().

PR-URL: nodejs/node#27762
Fixes: nodejs/node#27758
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
  • Loading branch information
cjihrig authored and aduh95 committed Aug 27, 2020
1 parent a3ca21e commit e81b9de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
{
files: [
'doc/api/esm.md',
'doc/api/modules.md',
'*.mjs',
'test/es-module/test-esm-example-loader.js',
],
Expand Down
8 changes: 4 additions & 4 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,11 @@ added:
* Returns: {[`require`][]} Require function

```js
const { createRequire } = require('module');
const requireUtil = createRequire(require.resolve('../src/utils/'));
import { createRequire } from 'module';
const require = createRequire(import.meta.url);

// Require `../src/utils/some-tool`
requireUtil('./some-tool');
// sibling-module.js is a CommonJS module.
const siblingModule = require('./sibling-module');
```
### module.createRequireFromPath(filename)
Expand Down

0 comments on commit e81b9de

Please sign in to comment.