ExpressJS closes connection on bigger data requests
I am trying to create an ExpressJS API that interpolates some data. I use Python requests to test my API. Everything works just fine if I send smaller datasets. However, when I send a bigger dataset Python (on Windows) returns a requests.exceptions.ChunkedEncodingError: "Connection broken: ConnectionResetError 10054
Exception.
The dataset size I am trying to send is 732808 bytes. I tried increasing the timeout limit and the datalimit, that did not help me:
app.use('/tests', test_router)
app.use(express.json({limit: '10mb'}))
app.listen(5000, () => console.log('Server running')).setTimeout(120000)
I tried to debug and found that none of my middleware gets invoked at all (router is "test_router" in code above).
router.get('/test_interpolation', (req, res) => {
console.log('Hello') //Never gets called
res = test_controller.do_something(req, res)
})
Why does ExpressJS not accept the request? Thank you for helping!
My first mistake was using router.get(). Apparently ExpressJS only accepts bigger datasets through a post request. Also, my middleware was not configured right either. This is what it looks like now:
app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ limit: '100mb' }));
app.use(bodyParser.json({ limit: '100mb' }));
app.use(
bodyParser.urlencoded({
limit: '100mb',
extended: true,
}),
);
I used npm body-parser for "bodyParser". It does give me a message that urlencode is deprecated, but this does not bother me right now.