From e81b9de20d9dcc16fd03e7dd790ddaae10dd8d32 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 18 May 2019 09:10:20 -0400 Subject: [PATCH] doc: improve createRequire() example Update the example to use import and import.meta.url instead of require() and require.resolve(). PR-URL: https://github.com/nodejs/node/pull/27762 Fixes: https://github.com/nodejs/node/issues/27758 Reviewed-By: James M Snell Reviewed-By: Anto Aravinth --- .eslintrc.js | 1 + doc/api/modules.md | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d13fb1709ba..b51b858cc68 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,6 +38,7 @@ module.exports = { { files: [ 'doc/api/esm.md', + 'doc/api/modules.md', '*.mjs', 'test/es-module/test-esm-example-loader.js', ], diff --git a/doc/api/modules.md b/doc/api/modules.md index 66e0b9f32dd..9b66eeeeee5 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -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)