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 trialcathy mitchell
8,249 Pointsexpress basics
this is challenge 2 with express basics:
Use the send method on the response object to return the posts object when the /blog route is requested.
app.get('/blog', function (req, res) { res.send() req.send(post) });
My error is: You need to pass the 'posts' object to the send() method on the response object.
'use strict';
var express = require('express');
var posts = require("./mock/posts.json");
var app = express();
app.get('/', function(req, res){
res.send("<h1>I Love Treehouse!</h1>");
});
app.listen(3000, function(){
console.log("The frontend server is running on port 3000!")
});
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Cathy! You're doing well here, but you've got an extraneous res.send()
method, and your variable name for your object is misspelled. Take a look:
app.get('/blog', function(req, res){
res.send(posts);
});
Upon accessing the /blog
URL this function will send a response containing the posts
object (as required by the challenge and initialized in the code). You're sending back a post
object, which isn't defined. Hope this helps!
Salwa Elmohandes
Full Stack JavaScript Techdegree Graduate 20,240 PointsJennifer Nordell maybe she used the => when I deleted the arrow function icon it works. I know It should work both ways.
cathy mitchell
8,249 Pointscathy mitchell
8,249 Pointsthat didn't work.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse Teachercathy mitchell I'm not sure what to tell you here. If I copy/paste this code into the challenge, it passes both steps without problem:
This is a working solution according to TTH. If it's still not passing even after copy/paste, you might have to contact support.