Wondering what’s next for npm?Check out our public roadmap! »

import-reloadTypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

$ npm install import-reload

USAGE

Example

// foo.ts
export const foo = { bar: 1 };
// 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:

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

Back in main:

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

API

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.

Install

npm i import-reload

DownloadsWeekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

6.81 kB

Total Files

4

Last publish

Collaborators

  • avatar