diff options
author | Myles Borins <myles.borins@gmail.com> | 2019-04-25 00:29:22 -0400 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-05-03 12:12:30 -0700 |
commit | 411063c6f5750f4a2243ef5154c589109d9b807c (patch) | |
tree | b6c682d3d1c53ab167e371894fab9303c008b4e9 /doc/api/modules.md | |
parent | 8cac945126a9db099609ca33bf6289f2d02257db (diff) | |
download | android-node-v8-411063c6f5750f4a2243ef5154c589109d9b807c.tar.gz android-node-v8-411063c6f5750f4a2243ef5154c589109d9b807c.tar.bz2 android-node-v8-411063c6f5750f4a2243ef5154c589109d9b807c.zip |
module: add createRequire method
This is an abstraction on top of creatRequireFromPath that can accept
both paths, URL Strings, and URL Objects.
PR-URL: https://github.com/nodejs/node/pull/27405
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc/api/modules.md')
-rw-r--r-- | doc/api/modules.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/api/modules.md b/doc/api/modules.md index 8638b137ad..4acead178e 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -905,15 +905,36 @@ by the [module wrapper][]. To access it, require the `Module` module: const builtin = require('module').builtinModules; ``` +### module.createRequire(filename) +<!-- YAML +added: REPLACEME +--> + +* `filename` {string|URL} Filename to be used to construct the require + function. Must be a file URL object, file URL string, or absolute path + string. +* Returns: {require} Require function + +```js +const { createRequire } = require('module'); +const requireUtil = createRequire(require.resolve('../src/utils/')); + +// Require `../src/utils/some-tool` +requireUtil('./some-tool'); +``` + ### module.createRequireFromPath(filename) <!-- YAML added: v10.12.0 +deprecated: REPLACEME --> * `filename` {string} Filename to be used to construct the relative require function. * Returns: {require} Require function +> Stability: 0 - Deprecated: Please use [`createRequire()`][] instead. + ```js const { createRequireFromPath } = require('module'); const requireUtil = createRequireFromPath('../src/utils/'); @@ -926,6 +947,7 @@ requireUtil('./some-tool'); [`Error`]: errors.html#errors_class_error [`__dirname`]: #modules_dirname [`__filename`]: #modules_filename +[`createRequire()`]: #modules_module_createrequire_filename [`module` object]: #modules_the_module_object [`path.dirname()`]: path.html#path_path_dirname_path [exports shortcut]: #modules_exports_shortcut |