As we all know, when you update a nodejs file and upload it to your server, it needs a restart to be applied -- but if you're using something like nodemon
where it automatically restarts your server, your clients that are logged in would need to refresh the screen.
So I was wondering, is there a way I could trigger a "logout" when my server goes down/is restarted so that at the minimum it just refreshes the clients so they know what's happened?
As it stands they'll broadcast undefined errors because theyre session has been lost?
I tried to validate using a function I have called authenticate
function authenticate(req,res,next) {
if (!req.session.loggedIn) {
fs.readFile('./html/login.html', "utf8", function(err, html) {
res.send(html);
});
} else next();
}
and here's how I call the function:
app.io.route('move', authenticate, function(req) {
But my server crashes because the parameters are undefined at that point.
Basically think of it like an onbeforeunload
event but instead of the browser, the server.