Wednesday, 5 July 2017

res.render is returning a 404 error on router.get

I'm building my first Node application and having some trouble displaying the page that I want with a GET request. I have installed ejs (opinions welcome on that!) so my understanding is that I do not need to define the 'views' folder. Here is my routes file so far:const express = require('express'); const router = express.Router(); const Event = require('../models/event') router.get('/'), function(req, res, next){ /* Event.find({}).then(function(events){ res.send(events); }); });*/ res.render('../../index'); }; router.post('/events', (req, res) => { Event.create(req.body); res.send({type: POST}) }); module.exports = router; The database is connecting just fine, which I can see with the code that I have commented out in the get request. But for some reason I can't render my index file. Here's my file tree.So I need to go up two levels, correct? Either way I've tried index, index.ejs, ../index, views/index, nothing has worked. What am I doing wrong?

Submitted July 05, 2017 at 02:17PM by flight19

No comments:

Post a Comment