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 trialDaryl Shy
2,536 PointsWhy does req.query return undefined?
// Postman----------------------------- // [GET] localhost:3000/color?=green [SEND] //------------------------------------------ var express = require('express');
var app = express(); app.use(function (req, res, next) { console.log("The leaves on the ground are", req.query.color); next(); });
var port = process.env.PORT || 3000;
app.listen(port, function () {
console.log(App is running on port ${port}!
);
});
3 Answers
Benjamin Barslev Nielsen
18,958 PointsThe request seems strange:
localhost:3000/color?=green
It should work with this request instead:
localhost:3000?color=green
This should solve the request problem, but you also need to fix the console.log in the last line, since you forget to use "" around the string, so a possible fix could be:
app.listen(port, function () { console.log("App is running on port " + port + "!"); });
J. MORENO
12,550 PointsThe request should have been - http://localhost:3000/?color=green
The ? was misplaced.
J. MORENO
12,550 Pointsafter cleaning up the code and using the proper request:
var express = require('express');
var app = express(); var port = process.env.PORT || 3000;
app.use(function (req, res, next) { console.log("The leaves on the ground are", req.query.color); next(); });
app.listen(port, function () {
console.log(App is running on port ${port}!
);
});
Jonathan Ankiewicz
17,901 PointsJonathan Ankiewicz
17,901 PointsI believe it should be
req.params.color