Im working on couple of sites, both have 2 versions, live one and dev one. http://timeprize.com and http://test.timeprize.com They both run on the same port and server, using express vhost.
My vhost app looks very simple, and is basically this:
var evh = require('express-vhost'),
express = require('express');
/*... some more variable declarations ...*/
if ( site_enabled('test.timeprize.com') ) {
/**/
evh.register('test.timeprize.com', function() {
var app = express();
app = require("../test_app/app.js").run_app(http);
return app;
}() );
};
if ( site_enabled('timeprize.com') ) {
evh.register('timeprize.com', function() {
var app = express();
app = require("../live_app/app.js").run_app(http);
return app;
}() );
};
/*... more sites below ...*/
Im running the code above using "forever" process.
And now the problem. Since the test site, and live site are both running on the same server/port using same process, how do i update/restart the test site, without interrupting the live site ?
To address the:
This shouldn't occur. Your server should throw an error when a second program attempts to listen to a port already occupied.
To answer the real question:
The answer is don't use forever. Yes, it's easy and whatever but for servers with multiple applications running in sync, the must use program is PM2
[sudo] npm i -g pm2
[sudo] pm2 start app.js
[sudo] pm2 restart [all|name]
OR
[sudo] pm2 gracefulReload [all|name]
Check out documentation