Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NodeJS: Cookie is undefined

I’m trying to make a simple GET request to my localhost:8080.
When I make the GET request with Postman, I set a simple cookie. Now, in the main file, I’ve:

var express = require('express');
var app = express();

const cookieParser = require('cookie-parser');
app.use(cookieParser()); 
const app_router = require('./routes/router');

app.use("/api", app_router);
app.use(express.static('public'));


app.listen(8080, function () {
    console.log('Outdoor Localization GNSS middleware.');
});

In routes/router.js I have:

var express = require('express')
const router = express.Router();
const axios = require('axios');
const url = 'http://10.10.0.145:80/api'

router.use(express.json());


router.get('/*', function (request, response) { 
   console.log(request.Cookie)

    axios
    .get(request_url)
    .then(res => {
    console.log(request.Cookie)
    })
    .catch(error => {
      console.error(error)
    })
});

The problem is that request.Cookie always return undefined…why is this happening?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you should be accessing the property request.cookies instead of request.Cookie

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading