I have mounted a Parse Server on an ubuntu, and every time I add a modification to the index.js I have to restart, which takes 4 or 5 seconds to come back to life.
Is there a more optimal way to add changes without dropping the server?
I have mounted a Parse Server on an ubuntu, and every time I add a modification to the index.js I have to restart, which takes 4 or 5 seconds to come back to life.
Is there a more optimal way to add changes without dropping the server?
For the example you asked (the connection to the base) there is a solution. Instead of having your index.js like this:
var dbMotor = require('my-sql'); // o require('pg-promise-strict');
var config = require('./config.json');
var dbOpen = dbMotor.connect(config.parametrosDb);
var app = require('express')();
app.get('/data', function(req, res){
dbOpen.query("SELECT ALL ... ", function(err, data){
res.end(data);
});
});
you can have a database wrapper that only restarts that part:
var dbMotor = require('my-sql'); // o require('pg-promise-strict');
var config;
var dbOpen;
var app = require('express')();
function start(){
config = require('./config.json');
dbOpen = dbMotor.connect(config.parametrosDb);
}
start(); // lee todo al inciar el servidor
app.get('/reset', function(req, res){
start(); // vuelve a leer todo al resetear
res.end("reset ok at "+new Date());
});
app.get('/data', function(req, res){
dbOpen.query("SELECT ALL ... ", function(err, data){
res.end(data);
});
});
node index.js
start
you have to see how much of the 4 or 5 seconds it takes tasks to be done again /reset
from the browser, you can choose other activators, for example a watchFile
that is observing if there were modifications in the configuration file. start
for each type of thing, one for the database, another to read disk templates, another to change ports, etc. There is no magic solution , everything has to be tested and programmed, someone pays for the cost , the programmer programming, the programmer waiting for it to start at each restart, the user with the low performance (of something that is all the time seeing if it changed), the user with the probability that something has an error.
install forever
sudo npm install forever --global
and then start your app (in debug mode) with:
forever -f -w index.js
then if you make any change in your index.js you will have an exit like this
error: restarting script because change changed
error: Forever detected script was killed by signal: SIGKILL
error: Script restart attempt #1
the flag -w tells node to be aware of any change in the index.js file and to restart it, interpreting it as an error but it is not.