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: #27762
Fixes: #27758
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
  • Loading branch information
cjihrig authored and BridgeAR committed May 21, 2019
1 parent 2bc177a commit 55fe340
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 @@ -39,6 +39,7 @@ module.exports = {
{
files: [
'doc/api/esm.md',
'doc/api/modules.md',
'test/es-module/test-esm-type-flag.js',
'test/es-module/test-esm-type-flag-alias.js',
'*.mjs',
Expand Down
8 changes: 4 additions & 4 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,11 @@ added: v12.2.0
* 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 55fe340

Please sign in to comment.