Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda