Why are my cookies not being set Node.JS and cookie-parser? -


so i've been working on project node.js , trying set cookie based of id passed variable - code working yesterday today can console log query.id fine yet cookie undefined , can't figure out why - dealt before , can shed light?

app.get('/home', function(req, res) { console.log(req.query.id); if (res.query != undefined && res.query.id != undefined) {     res.cookie('user_id', req.query.id);       res.send(req.cookies.user_id); }; console.log(req.cookies.user_id); var user_id = req.cookies.user_id; console.log(user_id); var project = []; retrieve_projects = connection.query('select * projects,    project_users project_users.user_id = '+user_id+' ,   project_users.project_id = projects.id' , user_id, function (err, result){     //console.log(result);     //throw err;     (var = 0; <= result.length; i++) {         if (result[i] != undefined) {             //console.log(result[i]);             var tempproject ={                 project_id: result[i].id,                 project_title: result[i].title,                 description: result[i].description,                 start_date: result[i].start_date,                 end_date: result[i].end_date,                 status: result[i].status,                 project_colour: result[i].project_colour             }                 project.push(tempproject);         }     }     //console.log(project);     res.render('home',     {             title: 'utasko | home',         project_data:project     }); });     }); 

please check line 3 of code, if statement checking res.query twice instead of req.query. res.query not exist, believe contents of if statement block not execute.

broken:

if (res.query != undefined && res.query.id != undefined) { 

fixed:

if (req.query != undefined && req.query.id != undefined) { 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -