This blog is primarily focus on Java fundamentals and the libraries built on top of Java programming language. Most of the post are example oriented, hope you have fun in reading my blog....:)
Showing posts with label response cookies. Show all posts
Showing posts with label response cookies. Show all posts
Friday, 15 March 2019
Thursday, 14 March 2019
Express: res.cookie(name, value [, options]): Set cookie name to value
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.
Subscribe to:
Posts (Atom)
