This is the home page or ('/') on localhost:3000. I wanted this home page to work in a way so that when a user logs in they will have their username displayed. Currently, this only works when the user logs in. However, I want to ignore the error if they are not logged in so that anyone could access the page without being logged in. I am using passport to authenticate users across a session if that help and you can view my home route and the snippet of where I'm executing the ejs in home.ejs file.
//Home page route in js
app.get('/',(req, res) => {
res.render('home.ejs', {name: req.user.username})
})
//.ejs file snipped
<li>
<%if(locals.name){%>
welcome <%=name %>
<form class="" action="/Users/logout?_method=DELETE" method="post">
<button type="submit" name="button">Logout</button>
</form>
<%}%>
</li>