“Express Request Body indefinido” Respostas de código

Express Post Body indefinido

// If you are using Express 4.16+ you don't have to import body-parser anymore. 
// You can do it just like this:

app.use(express.urlencoded({extended: true}));
app.use(express.json()) // To parse the incoming requests with JSON payloads
MassimoMx

Req.body é indefinido

var bodyParser = require('body-parser')
var app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())
Enthusiastic Earthworm

Express Request Body indefinido

npm install body-parser
// then in your app
var express = require('express')
var bodyParser = require('body-parser')
 
var app = express()
 
// create application/json parser
var jsonParser = bodyParser.json()
 
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
 
// POST /login gets urlencoded bodies
app.post('/login', urlencodedParser, function (req, res) {
  res.send('welcome, ' + req.body.username)
})
 
// POST /api/users gets JSON bodies
app.post('/api/users', jsonParser, function (req, res) {
  // create user in req.body
})
Almabek

Respostas semelhantes a “Express Request Body indefinido”

Perguntas semelhantes a “Express Request Body indefinido”

Mais respostas relacionadas para “Express Request Body indefinido” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código