NODE/EXPRESS/BODY-PARSER I’m not able to read the body, keeps giving UNDEFINED

Asked

Viewed 269 times

1

Well I’m going to post the index here for you to look at, I reworked the code and it worked for another purpose, but with this purpose of taking the information and sending it to the Undefined database, I don’t know what it could be.

insira o código aqui
const porta = 3003
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const bd = require('./callBd.js')
app.use(bodyParser.urlencoded({ extended: true}))
app.use(bodyParser.json());


app.get('/user', (req, res) =>{
    bd.execQuery('SELECT * FROM User', res);
})

app.get('/user/:id?',(req,res) => {
    bd.execQuery(`SELECT * FROM User where ID = ${req.params.id}`, res);
})


app.post('/user/:user?/:prof?/:pass?', (req, res) =>{
    const name = req.body.nome
    const prof = req.body.profissao
    const pass = req.body.password
    /**const name = req.params.user
    const prof = req.params.prof
    const pass = req.params.pass**/

    console.log(name,prof,pass)
    bd.execQuery(`INSERT INTO User(Name, Profission, Password) VALUES('${name}','${prof}','${pass}')`, res);
});

app.listen(porta,()=>{
   console.log(`Servidor está executando na porta ${porta}.`)
})

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

JÁ TENTEI USAR AS OUTRAS OPÇÕES COMO RAW NA POSTMAN MAIS TODAS DEVOLVEM UNDEFINED

inserir a descrição da imagem aqui

1 answer

1

Hello, good afternoon.

On the Postman "Body" option, check the "Row" option, and on the left side you will see the "Body" type option. Click on it and select "JSON(application/json)".

See the image below:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.