I have this code:
app.get("/dashboard", (request, response) =>{});
And It loads a pug file. I was wondering if I can use my session variable, which you call like this request.session.whateverisinthesession
, in it from my server.js file. If this is possible, it would be great if you could tell me how
Eddie
I have not used Pug before but when you render the Pug file you can add an object with the data you want to be rendered in your Pug file.
app.get("/dashboard", (req, res) => {
res.render('index', {
session: req.session.somesession
})
}
Then in your Pug file, you can use the session in the body or head by using session
. See https://expressjs.com/en/guide/using-template-engines.html for more help.
2 Likes