express send cookie code example
Example 1: set cookie in node
res.setHeader('Set-Cookie','visited=true; Max-Age=3000; HttpOnly, Secure');
Example 2: express get cookie
const cookieParser = require('cookie-parser');
const express = require('express');
const app = express();
app.use(cookieParser());
app.get('/', (req, res) => {
console.log('Cookies: ', req.cookies);
console.log('Signed Cookies: ', req.signedCookies);
});
app.listen(3000);
Example 3: express cookies
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser());
app.get('/', (req, res) => {
res.send(req.cookies);
});
app.listen(3000);