Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to set cookies in node js

res.cookie('cokkieName',randomNumber, { maxAge: 900000, httpOnly: true })

res.cookie('Cookie Name', 'Cookie Value', {Cookie Options Object})
Comment

Cookies In NodeJS

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;
Comment

cookies in express js

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);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: not getting any response with fetch javascript method 
Javascript :: find capital word in string javascript 
Javascript :: jquery after 
Javascript :: javascript change css 
Javascript :: mongodb aggregate node.js 
Javascript :: orbit controls drei 
Javascript :: vanilla javascript fade out 
Javascript :: how to loop an object in javascript 
Javascript :: lorem ipsum json api 
Javascript :: get params from route vuejs 
Javascript :: flask return status code 200 and json 
Javascript :: react private route 
Javascript :: react forms 
Javascript :: google map in react js 
Javascript :: javascript is array a subset of array 
Javascript :: javascript take last element of array 
Javascript :: convert arraybuffer to file javascript 
Javascript :: largest number javascript 
Javascript :: js map array to dictionary 
Javascript :: function range() as range js 
Javascript :: Javascript random password generator Exampe 
Javascript :: jquery li count in ul 
Javascript :: is a letter javascript 
Javascript :: setinterval stop onditional stop 
Javascript :: confirm javascript 
Javascript :: vuejs props 
Javascript :: how to change the color of a console.log in javascript 
Javascript :: javascript reduce 
Javascript :: export all functions from js file 
Javascript :: set dynamic route in link react js 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =