Example cookies in express

Example:

var express = require('express');

var cookieParser = require('cookie-parser');

var app = express();

app.use(cookieParser());

 

app.get('/', function (req, res) {

    console.log("Cookies: ", req.cookies);

    res.send('Hello World');

});

 

var server = app.listen(8080, function () {

    var host = server.address().address;

    var port = server.address().port;

 

    console.log("Server listening at http://%s:%s", host, port);

});

 

Run and go browser http://localhost:8080

 

C:\Nodejs>node express_cookie.js

Server listening at http://:::8080

Cookies:  { _ga: 'GA1.1.1739094391.1514373239' }

Cookies:  { _ga: 'GA1.1.1739094391.1514373239' }