WORKING CODE:
/public/dashboard.html
app.get("/dashboard", async (req, res) => {
try {
const statistics = await Statistics.findOne({});
const html = await ejs.renderFile(path.join(__dirname, 'public', 'dashboard.html'), { statistics });
res.send(html);
} catch (err) {
console.error('Error fetching statistics:', err);
res.status(500).send('Internal Server Error');
}
});
NOT WORKING CODE:
/public/dashboard.ejs
app.get("/dashboard.ejs ", async (req, res) => { // ive also tried without the .ejs extension
try {
const statistics = await Statistics.findOne({});
const html = await ejs.renderFile(path.join(__dirname, 'public', 'dashboard.ejs'), { statistics });
res.send(html);
} catch (err) {
console.error('Error fetching statistics:', err);
res.status(500).send('Internal Server Error');
}
});