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 trialjason limmm
8,009 Pointsh2 text not appearing
my h2 text isn't appearing i don't know why
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false}));
app.use(cookieParser());
app.set('view engine', 'pug');
const mainroute=require('./routes');
const cardroutes=require('./routes/card/cards')
app.use(mainroute);
app.use('/cards', cardroutes);
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.locals.error = err;
res.status(err.status);
res.render('error');
});
app.listen(3000, () => {
console.log('The application is running on localhost:3000!')
});
card.js
const express = require('express');
const router = express.Router();
const data = require('../../data/flashcardData.json').data;
const cards = data.cards;
router.get('/:id', (req, res) => {
const side = req.query.side;
const id = req.params.id;
const text =cards[id][side];
const hint = cards[id].hint;
const templateData = {text, hint};
res.render('card', templateData);
});
module.exports = router;
card.pug
extends layout.pug
block content
section#content
h2= text
if hint
p
i Hint: #{hint}
1 Answer
Rohald van Merode
Treehouse StaffHey jason limmm 👋
What route are you visiting to test this your code? You'll want to make sure that there is a query parameter present for the side
as Andrew explains around the 1:37 minute mark
When I paste your code into the provided project files everything seems to be working as expected when visiting a route like: http://localhost:3000/cards/2?side=question
Hope this helps.
jason limmm
8,009 Pointsjason limmm
8,009 Pointswhen i tried to run the server it said "Cannot set headers after they are sent to the client"
here is all of my files so that you see if there is any problem outside the 3 i gave
app.js
cards.js
index.js
card.pug