🔥 Hot Module Replacement for Node.js
This module adds hot module replacement support for node.js applications, it intended as an alternative to such tools like nodemon. Reloading modules while an application is running significantly faster than full reloading which in some cases may add additional downtime to a development process.
Inspired by this article https://codeburst.io/dont-use-nodemon-there-are-better-ways-fc016b50b45e
callbackFunction which will be called each time when some file was changed
optionsOptions object. Optional
debugShow list of modules which was removed from the cache. Default: false
watchDirRelative path to the directory to be watched recursively. Default: directory of the current module
const hmr = ;;
How to use it with frameworks
You should split your application into two parts first is server setup and second is application module. Below are examples of how to use it with some popular frameworks.
Express.js with HMR example
const express = ;const app = ;app;moduleexports = app;
const http = ;const hmr = ;let app;;const server = http;server;
Koa.js with HMR example
const Koa = ;const app = ;app;moduleexports = app;
const hmr = ;let callback;;const server = http;server;
In some cases, HMR may not work correctly with libraries which using some internal caching storage
Mongoose is the example of one. If you see this error message
Cannot overwrite `User` model once compiled the workaround could be add the following syntax to each model declaration, but in this case changes to the model will not be 'hot reloaded'.
moduleexports = mongoosemodelsUsers || mongoose;