Observing session create-destroy events in nodejs

I am using "express-session" and "memorystore". I want to log session create and destroy activities. My solution is, taking a snapshot of the current "sessionStorage" and a while later, compare it with the current "sessionStorage" and based on the differance, report session created, destroyed activites.

let sessionSnapshot;
function (req, res, next) {
    let currentSnapshot = req.sessionStore;
    let difference = sessionSnapshot.filter(x => !currentSnapshot.includes(x));
    // Report create/destroy activities based on difference.

Is there any other places / callbacks that I can track session create and destroy events ?
I am using "passport" as well.

52 thoughts on “Observing session create-destroy events in nodejs”