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

556
Views
Node /Express, How to configure bodyParser to use raw on certain routes only

I'm not quite sure if I am approaching this correctly, but my problem is, that I receive usually json data at my API endpoint, then I am creating a model instance from the json req.body data...and I am using MEAN stack..

The problem that I now have is, that one of the fields of my model is of mongoose-long datatype with 18 positions. However, the bodyParser parses the number and rounds the las 3 positions of the number. I use it for the _id field, so I am getting duplicate key errors.

I construct and send the data manually via Python for testing, and I use _ast_lib_eval(document) to strip all strings quotes from my constructed json document. Therefore, somehow the json bodyParser is getting the body and takes the number but cuts off (or rounds) the number fields because I guess, it does not support such long numbers natively...I could use another bodyParser for certain routes maybe... but I'm not sure how to configure that.

What is the best approach now? Do I have to use another parser and therefore send my data as plain text or raw for all api endpoints? That would mean I have to redo everything so that it fits the parser, right? The usual format is json....

or can I somehow get the "raw" data from the req.body before it is getting parsed from the bodyparser? That would be the best way to manually get the number out right.. but I don't know if there's a method to do that...

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Based on specification you are able to specific custom bodyparser on all endpoints

app.post('/some/special/route', bodyParser.json({verify:function(req,res,buf){req.rawBody=buf}}))
app.use(bodyParser.json())

Issue on gh

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!