Thank you for coming here i've been configing server by express and typescript i did success to make cookie like this code
app.get('/',req: Request, res: Response) => {
// res.cookie('park', 'juhong');
return res.send('cookie!');
}))
but when i try to get cookie by cookie-parser it doesn't work
const cookieParser = require('cookie-parser');
app.use(cookieParser);
app.get('/', (req: Request, res: Response) => {
console.log(req.cookies);
return res.send('cookie!');
})
How to get cookie in express typescript?
CodePudding user response:
set a cookie: res.cookie('name', value, { httpOnly: true, expires: expire })
get a cookie: req.cookies['cookie-name']
then in client version for example if you make a request with axios you need to enable property withCredentials