How can I edit on my server files without restarting nodejs when i want to see the changes?


Question

I'm trying to setup my own nodejs server, but I'm having a problem. I can't figure out how to see changes to my application without restarting it. Is there a way to edit the application and see changes live with node.js?

1
59
4/19/2013 10:56:04 PM

Accepted Answer

Check out Node-Supervisor. You can give it a collection of files to watch for changes, and it restarts your server if any of them change. It also restarts it if it crashes for some other reason.

"Hot-swapping" code is not enabled in NodeJS because it is so easy to accidentally end up with memory leaks or multiple copies of objects that aren't being garbage collected. Node is about making your programs accidentally fast, not accidentally leaky.

EDIT, 7 years after the fact: Disclaimer, I wrote node-supervisor, but had handed the project off to another maintainer before writing this answer.

50
10/19/2017 12:58:27 AM

Nodules is a module loader for Node that handles auto-reloading of modules without restarting the server (since that is what you were asking about):

http://github.com/kriszyp/nodules

Nodules does intelligent dependency tracking so the appropriate module factories are re-executed to preserve correct references when modules are reloaded without requiring a full restart.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon