res.cookie(name,
value [, options])
This method used to set the cookie name to value. The
value to the cookie can be a string or object converted to JSON.
Example
res.cookie('name', 'tobi', { domain: '.example.com',
path: '/admin', secure: true });
res.cookie('rememberme', '1', { expires: new
Date(Date.now() + 900000), httpOnly: true });
index.js
'use strict' const express = require('express') const app = express() app.get('/', (req, res) => { res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true }); res.send('Hello World') }) const port = 3000 app.listen(port, () => console.log(`Application started listening on port ${port}!`));
Run index.js.
Open the url ‘http://localhost:3000/’ in browser, you can
see below message.
No comments:
Post a Comment