https://github.com/75lb/load-module
Node's require with a few extra features
https://github.com/75lb/load-module
import javascript load module nodejs require
Last synced: 7 months ago
JSON representation
Node's require with a few extra features
- Host: GitHub
- URL: https://github.com/75lb/load-module
- Owner: 75lb
- License: mit
- Created: 2017-06-03T19:51:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-19T18:53:43.000Z (over 1 year ago)
- Last Synced: 2025-06-19T00:42:04.689Z (9 months ago)
- Topics: import, javascript, load, module, nodejs, require
- Language: JavaScript
- Homepage:
- Size: 651 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/load-module)
[](https://www.npmjs.org/package/load-module)
[](https://github.com/75lb/load-module/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/load-module/network/dependents?dependent_type=PACKAGE)
[](https://github.com/75lb/load-module/actions/workflows/node.js.yml)
[](https://github.com/feross/standard)
# load-module
Standard [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports) intended for runtime loading of user-defined modules (e.g. plugins).
- Search for modules in one or more specific folders.
- Specify a base folder from which to resolve from (e.g. the current working directory).
## Synopsis
```js
import { loadModule } from 'load-module'
const ViewClass = await loadModule('default-view', { paths: '~/my-view-folder'})
const view = new ViewClass()
```
## load-module
* [load-module](#module_load-module)
* [loadModule(specifier, options)](#module_load-module.loadModule)
* [loadModuleSpecifier(specifier)](#module_load-module.loadModuleSpecifier)
* [loadModuleResolvedFrom(specifier, paths)](#module_load-module.loadModuleResolvedFrom)
* [loadModuleRelativeTo(specifier, paths)](#module_load-module.loadModuleRelativeTo)
### loadModule(specifier, options)
**Kind**: exported function
| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid Node.js module specifier. |
| options.paths | `string[]` | One or more directories to pass to both `loadModuleResolvedFrom` and `loadModuleRelativeTo`. |
| options.resolvedFromPaths | `string[]` | Specific directories to pass to `loadModuleResolvedFrom`. |
| options.relativeToPaths | `string[]` | Specific directories to pass to `loadModuleRelativeTo`. |
### loadModuleSpecifier(specifier)
**Kind**: exported function
| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid Node.js module specifier. |
### loadModuleResolvedFrom(specifier, paths)
**Kind**: exported function
| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid Node.js module specifier. |
| paths | `string` \| `Array.` | One or more additional directories from which to resolve the supplied specifier from. |
### loadModuleRelativeTo(specifier, paths)
**Kind**: exported function
| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid module path. |
| paths | `string` \| `Array.` | One or more additional directories in which to search for the supplied module path. |
* * *
© 2017-24 Lloyd Brookes \<75pound@gmail.com\>.
Tested by [test-runner](https://github.com/test-runner-js/test-runner). Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).