import-reload
v1.0.3
Published
Module reloading for Node.js
Downloads
10
Maintainers
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
$ 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.