Node.js reload dependencies without reloading the application

I am writing an MMO server, and someone was able to create a server that, when it makes changes to the library files, automatically displays the next time the function is called without restarting the server itself.

(it keeps track of the change directory and automatically reloads the libraries without restarting)

He talks about what is called a node VM module (experimental), but I would like to ask if there are any modules that do this and what are the implications of this.

Few studies on VMs show that it is unstable. But how is this done? Writing a server update without restarting the application can really help in the development, since you will not need to return to the launch itself every time there is a problem, and you just need to change a small thing, and you can change the code and try it immediately on the client.

This is not browser related, its implementation of MMORPG client server.

So how is this possible?


Note: I know nodemon, supervisor, pm2 ... This is all a RESTART application so that it kills and spawns it again.


I tried to do something without using VM

var watch = require('watch')

// load data
var data = require('../lib/stuff.js')


watch.createMonitor('/...', function (monitor) {
    monitor.on("changed", function (f, curr, prev) {

      data = require('../lib/stuff.js')
      console.log(data)
    })
})

console.log(data)

What should be if I add functions in stuff.jstheory, it will reboot and should new functions be available now? WITHOUT WORK script?


, , Node.JS .

+4

Source: https://habr.com/ru/post/1547022/


All Articles