0
I’m trying to create a Postings in Node, where a post will have the following fields : Category, title and Description. The entity responsible for making this feature is called posts, which is configured as follows :
exports.up = function(knex) {
return knex.schema.createTable('posts', function(table){
//chave primária que se auto incrementa a cada post
table.increments()
table.string('category').notNullable()
table.string('title').notNullable()
table.string('description').notNullable()
})
};
Done this I created a route to perform this feature, which is as follows :
routes.post('/postagens', (request, response) => {
const data = request.body
console.log(data)
return response.json()
})
To test, I sent a request using the method POST with the content being sent in format JSON as follows :
{
"category": "stackoverflow",
"title": "erro à ser corrigido",
"description": "retorno undefined"
}
This being said, I receive the following content on console.log(data)
: Undefined.
How can I make to date receive the body of this my request ?
Are you using
express
?– Lucas Bittencourt
Thank you for the answer. I am using the express
– Gabriel Ribeiro Carneiro