Skip to content

Instantly share code, notes, and snippets.

@cjroth
Created September 1, 2014 08:38
Show Gist options
  • Save cjroth/6d86854b5db809c8746f to your computer and use it in GitHub Desktop.
Save cjroth/6d86854b5db809c8746f to your computer and use it in GitHub Desktop.
node/express last active middleware
module.exports = function() {
return function(req, res, next) {
if (!req.user) return next();
var sql = req.app.services.sql;
sql
.query('update users set last_active = $1 where id = $2;', [new Date(), req.user.id])
.on('error', function(err) {
console.error(err);
});
next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment