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

Cannot GET /cards error appears. I've tripled check everything and still can't find the issue. Please help. Thank you!

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 Grants tomb" });
});

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

index.pug

doctype html
html(lang="en")
  head
    title Flash Cards
  body
  header
    h1 Flash Cards
  section#content
    h2 Welcome, student!!!
  footer
    p An app to help you study

card.pug

doctype html
html(lang="en")
  head
    title Flash Cards
  body
  header
    h1 Flash Cards
  section#content
    h2= prompt
  footer
    p An app to help you study

Please let me know if you see anything I am doing incorrectly. Thank you. Aaron Noble

3 Answers

Change your code to this.

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

app.get your used cards and res.render you used card Both should be card This should fix your issue.

I saw that. I tried replacing it to '/card' even though the video has cards and that never worked. I just copied your code directly into my editor and it still doesn't work. I'm puzzled with this problem.

Sorry I finally realized why my route wasn't updating correctly. I wasn't running the server with 'nodemon' so it wasn't watching for the changes in the pug file. After running the server correctly the code you put works perfectly!. Thank you again.

Thanks for the nodemon reminder! That fixed things for me too

Same here, thanks!

What's weird is if I delete the root path completely and just have this below. It still shows my template on the localhost. I would think that this should throw an error since it's not referencing the index. pug file but it still showing the template.

const express = require('express');

const app = express();
app.set('view engine', 'pug');

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

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


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