Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!