Login form in node.js with session mangement

 connect(
      connect.cookieParser()
    , connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})
    , connect.favicon()
    , function(req, res, next){
      var sess = req.session;
      if (sess.views) {
        res.setHeader('Content-Type', 'text/html');
        res.write('<p>views: ' + sess.views + '</p>');
        res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
        res.end();
        sess.views++;
      } else {
        sess.views = 1;
        res.end('welcome to the session demo. refresh!');
      }
    }
  ).listen(3000);

Ref :

http://blog.nodejitsu.com/sessions-and-cookies-in-node

http://senchalabs.github.com/connect/middleware-session.html

Advertisements

About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in Node.js. Bookmark the permalink.

2 Responses to Login form in node.js with session mangement

  1. Ralt says:

    Thanks for your post, really !

    This is the only one I could find that correctly pointed out the solution to handle the length of the session. You made my day !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s