log last time login in node
<p>I am new to node . What I am trying to implement is to ask a user his name. When the user enters his name his session is created. On behind the time of user login is saved . Next time the user enters his name . His name plus the last time he logged in should be shown . My attempt was this </p>

<pre><code>var express = require('express');
var bodyParser = require('body-parser'); 
var expressSession = require('express-session');
var cookieParser = require('cookie-parser'); 

var app = express();

app.use(cookieParser());

app.use(expressSession({secret:'somesecrettokenhere'}));

app.use(bodyParser());

app.all('*', function findLastVisit(req, res, next) {
  if (req.session.visited)
    req.lastVisit = req.session.visited;

    req.session.visited = Date.now();


  next();
});

app.get('/', function(req, res){
  var html = '&lt;form action="/" method="post"&gt;' +
             'Your name: &lt;input type="text" name="userName"&gt;&lt;br&gt;' +
             '&lt;button type="submit"&gt;Submit&lt;/button&gt;' +
             '&lt;/form&gt;';
  if (req.session.userName) {
    html += '&lt;br&gt;Your username from your session is: ' + req.session.userName + '&lt;br&gt; And the last time you visited was ' + req.lastVisit;
  }
  res.send(html);
});

app.post('/', function(req, res){
  req.session.userName = req.body.userName;
  res.redirect('/');
});

app.listen(1337);
console.log("server is on 1337 bro");
</code></pre>

<p>Unfortunately my code always displays the current time only . I think I am doing a silly mistake . can anyone point out ?</p>