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

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

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