# load-module

> Standard dynamic imports with a few extra features

Latest version **5.0.0** (published 2024-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install load-module
pnpm add load-module
yarn add load-module
bun add load-module
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2024-07-19 |
| First published | 2017-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=12.20 |
| Dependencies | 1 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Lloyd Brookes |
| Maintainers | 75lb |
| Keywords | load, require, module, package, import, esm |

## Links

- npm: https://www.npmjs.com/package/load-module
- Repository: https://github.com/75lb/load-module
- Homepage: https://github.com/75lb/load-module#readme
- Issues: https://github.com/75lb/load-module/issues
- npm.io page: https://npm.io/package/load-module

## Dependencies (1)

- [array-back](https://npm.io/package/array-back.md) ^6.2.2

## Recent versions

- 5.0.0 (latest) — 2024-07-19
- 4.0.0-2 (next) — 2021-04-29
- 4.2.1 — 2021-08-13
- 4.2.0 — 2021-08-13
- 4.1.0 — 2021-07-24
- 4.0.1 — 2021-04-29
- 4.0.0 — 2021-04-29
- 4.0.0-1 — 2021-04-28
- 4.0.0-0 — 2021-04-24
- 3.0.1-0 — 2021-04-24
- 3.0.0 — 2019-12-03
- 2.0.2 — 2019-09-30
- 2.0.1 — 2019-06-05
- 2.0.0 — 2019-05-19
- 1.0.0 — 2018-07-01
- … 10 more at https://npm.io/package/load-module/versions

## README

[![view on npm](https://badgen.net/npm/v/load-module)](https://www.npmjs.org/package/load-module)
[![npm module downloads](https://badgen.net/npm/dt/load-module)](https://www.npmjs.org/package/load-module)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/load-module)](https://github.com/75lb/load-module/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/load-module)](https://github.com/75lb/load-module/network/dependents?dependent_type=PACKAGE)
[![Node.js CI](https://github.com/75lb/load-module/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/load-module/actions/workflows/node.js.yml)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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)

### <a name="module_load-module.loadModule">loadModule(specifier, options)</a>

**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`. |

<a name="module_load-module.loadModuleSpecifier"></a>

### loadModuleSpecifier(specifier)

**Kind**: exported function

| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid Node.js module specifier. |

<a name="module_load-module.loadModuleResolvedFrom"></a>

### loadModuleResolvedFrom(specifier, paths)

**Kind**: exported function

| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid Node.js module specifier. |
| paths | `string` \| `Array.<string>` | One or more additional directories from which to resolve the supplied specifier from. |

<a name="module_load-module.loadModuleRelativeTo"></a>

### loadModuleRelativeTo(specifier, paths)

**Kind**: exported function

| Param | Type | Description |
| --- | --- | --- |
| specifier | `string` | A valid module path. |
| paths | `string` \| `Array.<string>` | One or more additional directories in which to search for the supplied module path. |


* * *

&copy; 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).

---
_Source: https://npm.io/package/load-module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
