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 trialMichael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsDon't use body-parser
This course needs updating. You do not need to install anything to get the body with Express, at least not any more. You can use Express's own middleware to do this:
// middleware for parsing http payloads
app.use(express.urlencoded());
app.all('/hello', (req, res) => {
console.log(req.body)
res.render('hello', { name: req.body.username });
});
Also, since the /hello
route uses both GET and POST it makes a lot more sense to use Express's express.all
method which responds to all http verbs rather than having two separate routes for GET and POST. Again, update the course please.
Michael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsThanks, good call.
Alex Vien
7,615 PointsWhat is the purpose of the following parameter in res.render?
{ name: req.body.username }
7 Answers
Mathew Gries
7,072 PointsIt should be noted that in this video he explicitly has us install "express": "^4.15.2",
The express docs for express.urlencoded([options]) state: "This middleware is available in Express v4.16.0 onwards."
So either way, use the middleware from the video, or make sure to update your express version before trying this suggestion
jlampstack
23,932 PointsI'm glad I read this before investing my time on this. Thanks!
chrisshadrach
11,058 PointsThanks for this - is someone able to explain in simple terms that the difference is between extended "false" and "true" and when you'd use it?
Jacob Dahlberg
Python Development Techdegree Student 13,154 PointsThanks Michael Cook, terrific explanation of how to modify and use Express's middleware as well as the .all request!
jlampstack
23,932 PointsI was just reading the express docs. As of Jun-19-2020 express 5.x is still in the early stages of testing and isn't fully released yet. It's only in alpha mode. Your comments are appropriate for 5.x but personally, for now, I'd prefer following how Andrew Chalkley has laid out the lesson.
Soufiane Ez Zine
Full Stack JavaScript Techdegree Graduate 17,754 PointsI might be late but express.urlencoded() and get.all() are both part of express 4.x now
Ryan Agatep
Full Stack JavaScript Techdegree Graduate 17,705 PointsI can't get app.all();
to work with cookie-parser. I had to use app.post();
and app.get();
. Any thoughts on this?
Travis Alstrand
Treehouse Project ReviewerTHANK YOU!
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou may also want to make your suggestion directly to the Support staff.