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 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 91,253 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!