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 trialBrian Patterson
19,588 PointsCan't see a reference to the json sent.
I can't seem to see the reference to the json sent. Below is my app.js code.
"use strict;'
var express = require('express');
var app = express();
var routes = require('./routes');
var jsonParser = require('body-parser').json;
app.use(jsonParser());
app.use('/questions', routes);
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Express server is listening on port', port);
});
Below is my routes.js file.
'use strict';
var express = require('express');
var router = express.Router();
//GET /questions
//Route for questions
router.get('/', function(req, res) {
res.json({ response: 'You sent me a GET request' });
});
//POST /questions
// Route for creating questions
router.post('/', function(req, res) {
res.json({ response: 'You sent me a POST request' });
body: req.body;
});
//GET /questions/:id
// Route for specific questions
router.get('/:id', function(req, res) {
res.json({
response: 'You sent me a GET request for a specific ID' + req.params.id
});
});
module.exports = router;
I don;t see the reference to the json sent in the body pretty part of Postman.
1 Answer
Brian Patterson
19,588 PointsI worked it out. The POST function should be.
//POST /questions
// Route for creating questions
router.post('/', function(req, res) {
res.json({
response: 'You sent me a POST request',
body: req.body
});
});
Rich Donnellan
Treehouse Moderator 27,708 PointsRich Donnellan
Treehouse Moderator 27,708 PointsGood job!
FYI — To get syntax highlighting, add the language after the opening three backticks (e.g. ```
js
).