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 (2015) Developing Express Apps Like a Boss Add a new route to the app.

express 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.

app.js
'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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

that didn't work.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

cathy 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:

'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!")
});

app.get('/blog', function(req, res){
  res.send(posts);
});

This is a working solution according to TTH. If it's still not passing even after copy/paste, you might have to contact support. :sparkles:

Jennifer Nordell maybe she used the => when I deleted the arrow function icon it works. I know It should work both ways.