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

608
Views
Node.js - how to use a raw request body using Express

so I was making a RESTful API and I wanted to be able to receive raw json data (so I can use my api for mobile too), then from there save the data into my database (mongoDB).

But you see, there is this problem which I can't seem to fix and its that I'm not able to use the raw data as a json.

The code is simple

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

const app = express();

app.use(bodyParser.raw({inflate:true, limit: '100kb', type: 'application/json'});


app.post('/post', function(req, res){
 res.send(parse.JSON(req.body));
//to convert it to json but this doesn't seem to work
})

PS. I'm using postman to send the request as raw format

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

const app = express();

app.use(bodyParser.raw({inflate:true, limit: '100kb', type: 'application/json'});


app.post('/post', function(req, res){
 res.send(JSON.parse(req.body));
})

inside the res.send you have to use JSON.parse() instead of parse.JSON() which will throw an error as it is not correct

if you want to read more about JSON.parse you can visit mdn docs

over 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!