I have built a hot-reload plugin named 'dload' for node.js ,everything
looks fine .(project is here : https://github.com/yyrdl/dload )
But I am not sure if it's ok for production,could somebody give any
suggestions ?
Ideas :
Hot-reload means reload module when it is running , what's need to solve is
:
* reload new module , and update it globally
* release the old module and the resource that is created by the module.
If I know all the reference of target module ,then I can update the
module globally.
related code in `dload`:
```js
const monitors={};const newMonitor = funtion(tag){
var mon={};
monitors[tag]=mon;
return mon;}
exports.new = newMonitor;
```
and useage:
```js
const dload =require("dload");
const mo = dload.new();// `newMonitor` return an empty Object at first ,What's
important is that the object is also hold by `dload`.
mo.test_module = require("./test_module.js");//load target module,and assign
to the empty Object 'mo'
//suppose there is a method 'say' ,just invoke it
mo.test_module.say();
```
Suppose something changed in `./test_module.js` ,we need to reload it .
All we need to do is just remove the reference of old module in
`require.cache` and `mo` ,and require target module again, at final, assign
new module to `mo`. Because `mo` is also hold by `dload ` ,so it's a easy
thing.
PS:Be careful with the resource created by the old module, like a
connection pool or other else .
There are four test cases
in https://github.com/yyrdl/dload/tree/master/example :
* `test_update_and_memory.js` : test if it will update target module
successfully ,and if it will cause memory leak.
* `test_multi_rely.js` : test if there is impact when reload a module
which will no longer use `module1` which is also used by other modules
* `test_module_with_status.js` test module with status ,such as an counter
* 'test_server.js' will start a simple http server powered by express ,
and the only router `./server/router.js` will be changed and reload for
many times. At the same time ,it will start many request at the same time
to check if the reloading is work . And use another module `easy-monitor`
to check if there is a memory leak .
Suggestions Wanted ! ^_^
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/1fd8f53a-0012-46b2-8008-81fe1e1f6f68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.