Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics Using Templates with Express Express’s Response.render Method

Gillian Nieh
Gillian Nieh
5,709 Points

Internal Server Error

I am having trouble running app.js after this step. I keep getting an internal server (500) error saying "Failed to lookup view "index" in views directory "/Users/gilliannieh/views"

Why is the index.pug directed to the views directory? How do I get it to the flashcards folder?

Here is my app.js code:

const express = require('express');

const app = express();

app.get('/', (req, res) => {
    res.send('<h1>I love Treehouse!</h1>');
});

app.get('/hello', (req, res) => {
    res.send('<h1>Hello, Gilli!</h1>');
});

app.listen(3000, () => {
    console.log('The application is running on localhost:3000')
});

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,825 Points

2 things to check for. :-)

Do you have an index.pug file in a views directory?

Also I believe you need a reference to the pug templating engine in an app.set() method.

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

Hopefully that'll be enough to fix your server error and get the view to render in the browser.

Gillian Nieh
Gillian Nieh
5,709 Points

thank you! this really helped. I'm having the same issue with the hello.pug file later on in the course... it says: Failed to lookup view "hello" in views directory "/Users/gilliannieh/views" even when I have the hello.pug file in the views folder!