По какой-то причине я не могу понять, почему мой bodyParser не выполняет синтаксический анализ моих запросов из моего API (заголовок и содержимое).Они выглядят как undefined
app.js
const EXPRESS = require('express');
const FEED_ROUTES = require('./routes/feed');
const BODY_PARSER = require('body-parser');
const APP = EXPRESS();
APP.use(BODY_PARSER.json());
APP.use(BODY_PARSER.urlencoded({ extended: false }));
APP.use('/feed', FEED_ROUTES);
APP.listen(8080);
контроллер js
exports.getPosts = (req, res, next) => {
res
.status(200)
.json({ posts: [{ title: 'test', content: 'This is a post ' }] });
};
exports.createPost = (req, res, next) => {
const title = req.body.title;
const content = req.body.content;
console.log(title);
res.status(201).json({
message: 'Post created succesfully!',
post: { id: new Date().toISOString(), title: title, content: content }
});
};
POSTMAN печатает это:
{
"message": "Post created succesfully!",
"post": {
"id": "2019-07-09T00:24:57.129Z"
}
}
РАБОТАЕТ ![enter image description here](https://i.stack.imgur.com/1o4hz.png)
НЕ РАБОТАЕТ ![enter image description here](https://i.stack.imgur.com/AuhKJ.png)