summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2018-03-14 18:36:59 -0500
committerGus Caplan <me@gus.host>2018-09-14 11:34:17 -0500
commit246f6332e5a5f395d1e39a3594ee5d6fe869d622 (patch)
treec38ec08ac27b46cebfcffc05cd3127b749ab3f25 /doc
parente636addc3f88766b705349c90c91fa655ebfe7f9 (diff)
downloadandroid-node-v8-246f6332e5a5f395d1e39a3594ee5d6fe869d622.tar.gz
android-node-v8-246f6332e5a5f395d1e39a3594ee5d6fe869d622.tar.bz2
android-node-v8-246f6332e5a5f395d1e39a3594ee5d6fe869d622.zip
module: add createRequireFunction method
PR-URL: https://github.com/nodejs/node/pull/19360 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/modules.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/modules.md b/doc/api/modules.md
index f7934706d6..9919a67516 100644
--- a/doc/api/modules.md
+++ b/doc/api/modules.md
@@ -888,12 +888,30 @@ by the [module wrapper][]. To access it, require the `Module` module:
const builtin = require('module').builtinModules;
```
+### module.createRequireFromPath(filename)
+<!-- YAML
+added: REPLACEME
+-->
+
+* `filename` {string} Filename to be used to construct the relative require
+ function.
+* Returns: {[`require`][]} Require function
+
+```js
+const { createRequireFromPath } = require('module');
+const requireUtil = createRequireFromPath('../src/utils');
+
+// require `../src/utils/some-tool`
+requireUtil('./some-tool');
+```
+
[`__dirname`]: #modules_dirname
[`__filename`]: #modules_filename
[`Error`]: errors.html#errors_class_error
[`module` object]: #modules_the_module_object
[`path.dirname()`]: path.html#path_path_dirname_path
[GLOBAL_FOLDERS]: #modules_loading_from_the_global_folders
+[`require`]: #modules_require
[exports shortcut]: #modules_exports_shortcut
[module resolution]: #modules_all_together
[module wrapper]: #modules_the_module_wrapper