0

In nodejs is there a mechanism for dynamically having code that checks for updates and then runs said updates?

For example, I've got a distributed computing network with dozens (and plan to expand to hundreds) of workers.

When I update the 'worker' code, in order to actively implement on all the worker systems, I need to go to each system and stop node, copy the updated file, and then restart node.

I was thinking I could wrap the entire thing in a wrapper that goes out and periodically checks for updates (or just gets them via an HTTP request from a master server). When it sees new code, it unloads the currently runny process, grabs the new code, and starts a new process with that code... but I'm unsure how to dynamically unload and reload code in nodejs. Perhaps a call to an exec?

Questions such as Loading remote js file using require with node.js are similar... but not exactly what I'm looking for - as those are only loading remote files on startup.

Guidance?

8
  • would Dynamic import be useful? Commented Sep 20, 2020 at 2:49
  • Would dynamic import allow 'unloading' previous imported modules? Commented Sep 20, 2020 at 2:53
  • Implement CI/CD, the moment you push your code on git trigger deployment on node servers. Commented Sep 20, 2020 at 3:18
  • You cannot unload previously loaded modules in node.js. Once the interpreter has loaded their code, you can't "unload" it from memory. Generally, one will restart the node.js process to load new code. If you use clustering, you can shut down one server, upgrade it, start it up, shut down another, upgrade it, start it up, etc... and go without interrupting service. If you don't use clustering, you can manually bring up a second server, change a load balancer or proxy to now point at it, upgrade the first and reverse. Commented Sep 20, 2020 at 3:35
  • 1
    The moment it gets deployed, new code will run (technically new instance will start) also if you create your deployment scripts in manner their will be 0 downtime. Commented Sep 21, 2020 at 4:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.