res.cookie('cokkieName',randomNumber, { maxAge: 900000, httpOnly: true })
res.cookie('Cookie Name', 'Cookie Value', {Cookie Options Object})
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get("/set", function(req, res, next)
{
res.cookie("a", "hello world");
res.json({a: req.cookies.a});
});
router.get("/get", function(req, res, next)
{
res.json({a: req.cookies.a});
});
module.exports = router;
var cookieParser = require('cookie-parser');
var express = require('express');
var app = express();
var PORT = 3000;
app.use(cookieParser());
app.get('/user', function (req, res) {
req.cookies.name='Gourav';
req.cookies.age=12;
console.log(req.cookies);
res.send();
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});