I am facing an issue with the code in my index.ejs file. The current code snippet is as follows:
var current_user = <%= user %>
In my node.js file, I have the following code:
app.get("/", function(req, res){
res.locals.user = req.user
res.render("index")
})
However, when I view the page, I see that it displays "var current_user = [object Object]". Upon trying to stringify the user object using this code:
var current_user = <%= JSON.stringify(user) %>
The result is:
var current_user = {"__v":0,"_id":"50bc01938f164ee80b000001","agents":...
I am looking for a way to pass a JSON object that will be easily readable by JavaScript. Is there a solution for this?