Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Deeper into Routing with Express POST Requests

Getting error for "hello" route

It's throwing "Error: Failed to lookup view "hello" in views directory" (shortened version of the error) whenever I go to localhost:3000/hello Here is my code: app.js:

const express = require('express');

const app = express();

app.set('view engine', 'pug');

app.get('/', (req, res) => {
    res.render('index'); 
});

app.get('/cards', (req, res) => {
    res.render('card', { prompt: "Who is buried in Grant's tomb?"}); 
});

app.get('/hello', (req, res) => {
    res.render('hello'); 
});
app.listen(3000, () => {
    console.log('The application is running on localhost:3000');
});

hello.pug:

extends layout

block content
    h2 HOWDY

Can someone help? Thanks.

1 Answer

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey babyoscar , I can't tell what's wrong based on what I can see here. But if you share a link to a repo with your files or a workplace snapshot link, I should be able to run the app locally and determine where the issue is. :thumbsup:

Okay, my snapshot is https://w.trhou.se/leavdvflhq

I figured it out, I put hello.pug in views/includes instead of views.

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Well done, babyoscar! Way to stick with it and sort it out. Very developer like! And sorry about not getting back to you on this. I don't believe I ever received a notification of your response. Or if I did, it got accidentally deleted somehow. Either way, apologies for that. And keep up the great work. :thumbsup:

Thank you!