Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Receiving POST data with Express.js sent by angular2 app

I have following code on Node.js:

app.post('/register', function(req, res) {
  console.log(req.body);

But it appears that req object does not have body property.

With angular2 I am sending stringified JSON with Content-Type:application/json

Angular code looks like this:

this.http.post(
  "http://url.com",
  JSON.stringify(data_obj), {headers:{'Content-Type': 
  'application/json'}}).subscribe((res:Response) => this.extractData(res));

Thanks

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The NodeJS application does not have bodyParser so it is unable to parse the body of the request. Do this in your NodeJS application

Install body-parser

npm install body-parser --save

Add to nodeJS app

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

var app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
about 4 years ago · Santiago Trujillo Relatório

0

You have to use the body parser middleware in your app:

https://github.com/expressjs/body-parser

you can install it with this command: npm install body-parser --save

for example you can write this code to your main file:

let bodyParser = require('body-parser')

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

This is a basic configuration for the body parser middleware, it parse POST parameters into req.body.

If you want to learn more about the configurations of body parser, read the associate doc into the github repo.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda