Skip to content

Commit

Permalink
doc: align code example with actual code behavior
Browse files Browse the repository at this point in the history
module.createRequireFromPath() takes a filename as argument.
But the accompanying code example in the documentation makes it seem
like it can take a directory argument as well.
However, if a directory is passed as argument instead of a filename,
then the function does not work as expected.

Therefore, the fix is to make explicit in the code example that
only filenames could be passed to module.createRequireFromPath()
and not directory names.

Fixes: #23710
Refs: #24763 (comment)
  • Loading branch information
Antony J committed Mar 12, 2019
1 parent f2064df commit 72d0853
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ added: v10.12.0

```js
const { createRequireFromPath } = require('module');
const requireUtil = createRequireFromPath('../src/utils');
const requireUtil = createRequireFromPath('../src/utils/index.js');

// Require `../src/utils/some-tool`
requireUtil('./some-tool');
Expand Down

0 comments on commit 72d0853

Please sign in to comment.