# import-reload

> Module reloading for Node.js

Latest version **1.0.3** (published 2020-03-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install import-reload
pnpm add import-reload
yarn add import-reload
bun add import-reload
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-03-29 |
| First published | 2020-03-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Harsh Pandey |
| Maintainers | hpx7 |
| Keywords | hot, module, replacement, import, require, dynamic, reload |

## Links

- npm: https://www.npmjs.com/package/import-reload
- Repository: https://github.com/hpx7/import-reload
- Homepage: https://github.com/hpx7/import-reload#readme
- Issues: https://github.com/hpx7/import-reload/issues
- npm.io page: https://npm.io/package/import-reload

## Recent versions

- 1.0.3 (latest) — 2020-03-29
- 1.0.2 — 2020-03-29
- 1.0.1 — 2020-03-29
- 1.0.0 — 2020-03-29

## README

## IMPORT-RELOAD

Module reloading for Node.js

`import-reload` is a NPM module that lets you live-relaod modules when they are modified without requiring server restart.

## INSTALL

```shell
$ npm install import-reload
```

## USAGE

### Example

```ts
// foo.ts
export const foo = { bar: 1 };
```

```ts
// main.ts
import { reload } from "import-reload";

const foo = await reload(
  () => import("./foo"),
  Foo => Foo.foo
);

console.log(foo.bar); // outputs 1
```

Then modify foo.ts:

```ts
// foo.ts
export const foo = { bar: 2 };
```

Back in main:

```ts
console.log(foo.bar); // outputs 2
```

## API

```ts
reload<U, T extends object>(importFn: () => Promise<U>, extractFn: (module: U) => T): Promise<T>;
```

`importFn` should use the dynamic import function, e.g. `() => import("./module)`.

`extractFn` takes in the module returned by the import and returns the object to be used by the program.

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