I am having a client and a server node written in express. The client communicates with server using request module, the server will send response back to the client. Here in server code I am sending cookie back to the client. But I am unable to see the cookies in the browser. In client req.cookies is giving {}
Server code:
var express = require('express');
var cookieParser = require('cookie-parser');
var app = express();
app.use(cookieParser());
app.get('/test-cookie', function(req, res) {
res.cookie('abc', 'xyz').send('Cookie is set');
});
app.listen(9000);
Client code:
var express = require('express');
var request = require('request');
var cookieParser = require('cookie-parser');
var app = express();
app.use(cookieParser());
app.get('/', function(req, res) {
request({
url: 'http://localhost:9000/test-cookie',
method: 'GET'
}, function(error, response, body) {
if (error) {
res.send({
msg: error
});
} else {
if (200 == response.statusCode) {
console.log(req.cookies);
}
}
});
});
app.listen(7000);