Friday 29 November 2019

Express JS - Passing variable value to view

Hey there, I'm somewhat new to Express and I'm having trouble understanding how I would pass a variable outside a function to the view.Here's where I'm defining the variable: hasVoted(steamid).then(results => { var voted = parseInt(results) // This is the variable I wish to use }) }) I want to pass it to the view, the attempt I've tried here has failed (I assume because my variable definition is in a local scope)app.get('/', function(req, res){ res.render('index', { user: req.user }, { isvote: voted }); }); Is there another option for me to pass data to the view, or can I somehow make my variable global so I can pass it to res.render?

Submitted November 29, 2019 at 07:18PM by AyjayMartin

No comments:

Post a Comment