I am working on an Airbnb-like project using Express.js. Initially, everything worked fine, including passing variables to navbar.ejs using middleware. However, after connecting to an online MongoDB database, I started encountering the following issue:
21| <%- include(“../includes/navbar.ejs”) %>
The variable that I expect to access in navbar.ejs is no longer available. I have followed the correct syntax and used an npm package for handling local variables in Express, but the error persists.
Here are the steps I followed:
Created middleware to pass variables to all routes.
Tried using the include statement in my views to reference navbar.ejs.
Connected MongoDB via Mongoose with a proper connection string.
Before connecting to MongoDB, everything was working as expected, so I’m not sure what changed.