0

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?

Mavorus
  • 119
  • 1
  • 2
  • 13
  • You're thinking of this: [node-inspector](https://github.com/dannycoates/node-inspector#readme). The live edits happen through the Node.js debugger interface. I'm not sure if it would be feasible to use this route for actual code deployment, but let's see what answers you get. – lanzz Aug 31 '12 at 08:16
  • Ah.. yes... the more complex my app/server gets the harder it is going to be to mess around with small bits of code that fire/are responsible for certain states... having to restart the server and "play out" to that point is such a massive hassle. Besides node-inspector is there anything out there actually designed for coding on the fly and deploying? And if not deploying then at least as a sort of real-time IDE? – Mavorus Aug 31 '12 at 09:18

3 Answers3

0

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.

Community
  • 1
  • 1
Rem.co
  • 3,813
  • 3
  • 29
  • 37
  • Asker actually wants to hot-edit code without restarting the app (presumably to avoid losing volatile state or to avoid (even short) downtime). – lanzz Aug 31 '12 at 08:17
  • @lanzz Ah yes, I think you're right. I've misread/misinterpreted the question first time I read it. I highly doubt if such a thing is possible on a production node instance though; If it is I'd be happy to know about it as well (and I'll delete this answer because then this one is obviously incorrect. Until then I'm convinced this is one of the few safe ways to achieve a reliable file watch). – Rem.co Aug 31 '12 at 08:25
0

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

Community
  • 1
  • 1
madflow
  • 7,718
  • 3
  • 39
  • 54
  • I'm aiming for "live" modification... your proposal just restarts the server on code change which is what i'm doing now already.. – Mavorus Aug 31 '12 at 09:06
0

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

UenX
  • 162
  • 10