Mavorus
Mavorus

Reputation: 119

Live/Hot node.js server source code editing

I have a problem.

My problem is that every time I make changes to my node.js server code, I have to restart the entire thing to see the results.

Instead of this, I remember seeing something about being able to pipe chrome directly into the server's source code, and "Hot edit" it. That is to say, changes to the code immediately take effect and the server keeps runnings.

I hope that I am being clear.

It would be a real time saver to directly edit code (especially for small things) while the server is actually running and have it instantly take effect.

Does anyone know how to do this?

Upvotes: 0

Views: 2831

Answers (3)

UenX
UenX

Reputation: 162

Yes, there is such thing.

Just take advantage of the evil-so-called eval() function of Javascript. (You might need something like websocket to connect with the server and alert it about the change)

I am on the half-way of implement the same feature, but there are a lot of things to consider if you want to reserve the server states (current values of variables for example)

ABOUT THE pipe-to-chrome part May be this was what you mentioned? https://github.com/node-inspector/node-inspector/wiki/LiveEdit

Upvotes: 0

madflow
madflow

Reputation: 8490

I do not quite understand the pipe-to-chrome part... But there seems to be a node module which listens to changes of userdefined files and restarts the server automatically:

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

https://github.com/isaacs/node-supervisor

Upvotes: 0

Rem.co
Rem.co

Reputation: 3821

See my answer to my own question that answers this question: https://stackoverflow.com/a/11157223/813718

In short, there's a npm module named forever which does what you want. It can monitor the source files and restart the node instance when a change has been detected.

Upvotes: 0

Related Questions