yandex
loader

please wait

  • Atul Kasana Mar-14-2019 06:56:23 AM ( 1 week ago )

    In my application, I need to set a cookie using the express framework.I have tried the following code but it's not setting the cookie.

    Can anyone help me to do this?

    var express = require('express'), http = require('http');
    var app = express();
    app.configure(function(){
          app.use(express.cookieParser());
          app.use(express.static(__dirname + '/public'));
    
          app.use(function (req, res) {
               var randomNumber=Math.random().toString();
               randomNumber=randomNumber.substring(2,randomNumber.length);
               res.cookie('cokkieName',randomNumber, { maxAge: 900000, httpOnly: true })
    
               console.log('cookie have created successfully');
          });
    
    });
    
    var server = http.createServer(app);
    var io = require('socket.io').listen(server);
    server.listen(5555);

Please login

Similar Discussion

Recommended For You