Suppose I write a module handler.js as Express.js middleware:
var info = {};
infohandler.setinfo = function(i){ info[i] = Math.random(); }
infohandler.saveinfo = function(){ fs.writeFileSync("info.json", info); }
function handler(req, res, next){ // here are some operation call to infohandler according to req. }
module.exports = handler;
And in app.js I import this handler.js:
var handler = require("handler");
I want to save some information to a file right before server shutdown. How can I do this?