title: Login and Logout session with nodejs and html
body: <p>I want to develop a login and logout session using nodejs server and html as frontend.I followed this tutorial <a href="https://codeforgeek.com/2014/09/manage-session-using-node-js-express-4/" rel="nofollow">https://codeforgeek.com/2014/09/manage-session-using-node-js-express-4/</a>
  My code is below
  server.js  </p>
  
  <pre><code>var express     =   require('express');  
  var session     =   require('express-session');  
  var bodyParser      =   require('body-parser');  
  var app         =   express();
  
  app.use(express.static(__dirname + '/public'));
  app.set('views', __dirname + '/views');
  app.engine('html', require('ejs').renderFile);
  
  app.use(session({secret: 'ssshhhhh',saveUninitialized: true,resave: true}));
  app.use(bodyParser.json());      
  app.use(bodyParser.urlencoded({extended: true}));
  
  var sess;
  
  app.get('/',function(req,res){  
      sess=req.session;  
      if(sess.email)  
      {  
          res.redirect('/admin');  
      }  
      else{  
      res.render('index.html');   
      }  
  });
  
  app.post('/login',function(req,res){  
      sess=req.session;     
      sess.email=req.body.email;  
      res.end('done');  
  });
  
  app.get('/admin',function(req,res){  
      sess=req.session;  
      if(sess.email)      
      {   
          //res.render('lg.html');  
          res.write('&lt;h1&gt;Hello '+sess.email+'&lt;/h1&gt;&lt;br&gt;');  
          res.end('&lt;a href='+'/logout'+'&gt;Logout&lt;/a&gt;');  
      }  
      else  
      {  
          res.write('&lt;h1&gt;Please login first.&lt;/h1&gt;');    
          res.end('&lt;a href='+'/'+'&gt;Login&lt;/a&gt;');    
      }    
  
  });  
  
  app.get('/logout',function(req,res){    
      req.session.destroy(function(err){  
          if(err){  
              console.log(err);  
          }  
          else  
          {  
              res.redirect('/');  
          }  
      });  
  
  });  
  app.listen(3000,function(){  
      console.log("App Started on PORT 3000");  
  }) 
  </code></pre>
  
  <p>The code is working well,it is logging in and logout properly but my problem is when i login if iam redirecting the admin page to my html page by placing a logout button iam not able to logout from there.Please Help me out.</p>