用户会话在node.js中

我有一个用户名密码字段的表单,它将用户名和密码存储在node.js中我如何跟踪单个用户login的次数。我想输出用户名旁边的用户数量login用户列表

index.js:

var loggedInUsers = {}; var LoggedIn = 'TheUserIsLoggedIn'; function index(req, res) { if (req.session.username) { res.redirect("/users"); } else { debugger; res.render('index', { title: 'COMP 2406 Session Demo', error: req.query.error }); } } function users(req, res) { if (req.session.username) { res.render("account.jade", {username:req.session.username, title:"Account", loggedInUsers: loggedInUsers}); } else { res.redirect("/?error=Not Logged In"); } }; function login(req, res) { var username = req.body.username; req.session.username = username; loggedInUsers[username] = LoggedIn; res.redirect("/users") } function logout(req, res) { delete loggedInUsers[req.session.username]; req.session.destroy(function(err){ if(err){ console.log("Error: %s", err); } }); res.redirect("/"); } exports.index = index; exports.users = users; exports.login = login; exports.logout = logout; 

       

网上收集的解决方案 "用户会话在node.js中"