Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying updates to production node.js code

Tags:

node.js

This may be a basic question, but how do I go about effeciently deploying updates to currently running node.js code?

I'm coming from a PHP, JavaScript (client-side) background, where I can just overwrite files when they need updating and the changes are instantly available on the produciton site.

But in node.js I have to overwrite the existing files, then shut-down and the re-launch the application. Should I be worried by potential downtime in this? To me it seems like a more risky approach than the PHP (scripting) way. Unless I have a server cluster, where I can take down one server at a time for updates.

What kind of strategies are available for this?

like image 705
Mads Mogenshøj Avatar asked Oct 16 '10 08:10

Mads Mogenshøj


2 Answers

In my case it's pretty much:

svn up; monit restart node

This Node server is acting as a comet server with long polling clients, so clients just reconnect like they normally would. The first thing the Node server does is grab the current state info from the database, so everything is running smoothly in no time.

I don't think this is really any riskier than doing an svn up to update a bunch of PHP files. If anything it's a little bit safer. When you're updating a big php project, there's a chance (if it's a high traffic site it's basically a 100% chance) that you could be getting requests over the web server while you're still updating. This means that you would be running updated and out-of-date code in the same request. At least with the Node approach, you can update everything and restart the Node server and know that all your code is up to date.

like image 196
joeynelson Avatar answered Sep 22 '22 15:09

joeynelson


I wouldn't worry too much about downtime, you should be able to keep this so short that chances are no one will notice (kill the process and re-launch it in a bash script or something if you want to keep it to a fraction of a second).

Of more concern however is that many Node applications keep a lot of state information in memory which you're going to lose when you restart it. For example if you were running a chat application it might not remember who users were talking to or what channels/rooms they were in. Dealing with this is more of a design issue though, and very application specific.

like image 44
russell_h Avatar answered Sep 25 '22 15:09

russell_h