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 trialerika harvey
Courses Plus Student 14,540 PointsTHE QUESTION seems misleading, and I don't know quite how to answer it
it asks us to inject the posts object into our template . There is no Jade template to work with so I rendered a blog page with the title and "post", {post:posst} just like we did when following along. I"m confused as to what it is really asking me to do.
'use strict';
var express = require('express'),
posts = require('./mock/posts.json');
var app = express();
app.set('view engine', 'jade');
app.set('views', __dirname + '/templates')
app.get('/', function(req, res){
res.render('main');
});
app.get('/blog/:title', function(req,res){
var title = req.params.title;
if(title === undefined){
res.status(503);
res.send("this is under construction")
} else{
var post = posts[title] || {};
res.render('post',{post:post})
};
});
app.listen(3000, function() {
console.log("The frontend server is running on port 3000!");
});
3 Answers
Aaron Endsley
Courses Plus Student 17,625 PointsI figured it out, so posts is already a variable so you do not need to redeclare posts, however you do need to insert posts the same way you did to title, then you need to go ahead and do {posts:posts} the first posts is your variable posts which contains your posts.json call
here is the code
'use strict';
var express = require('express'),
posts = require('./mock/posts.json');
var app = express();
app.set('view engine', 'jade');
app.set('views', __dirname + '/templates')
app.get('/:posts?', function(req, res){
res.render('main', {posts:posts})
});
app.listen(3000, function() {
console.log("The frontend server is running on port 3000!");
});
erika harvey
Courses Plus Student 14,540 Pointsthanks to the both of you! i appreciate it!
James Gill
Courses Plus Student 34,936 PointsErika,
The answer's in the video preceding the challenge; Huston gives the exact example you need in the second half of the video. Give it a try, I bet you can figure it out. It's a very small bit of code.
Aaron Endsley
Courses Plus Student 17,625 PointsAaron Endsley
Courses Plus Student 17,625 PointsDid you ever get this to work, I am having trouble with this code challenge as well.