Consider this code:
const express = require('express')
const app = express()
const port = 3000
app.get('/foo/:bar', (req, res) => {
res.on('finish', () => console.log('onFinish: ' + req.params.bar));
// uncaught exception
'nothing' in undefined;
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
curl http://localhost:3000/foo/blablabla will cause Express to:
- Send HTTP 500 (expected)
- Crash (not expected)
==> TypeError: Cannot read properties of undefined (reading 'bar')
After the uncaught exception, req.params is undefined (among other req parameters, not listed here). Thus, trying to access bar from undefined is also an exception, causing the server to crash and terminate.
Looks like Express "clears" some variables in the req object.
Consider this code:
curl http://localhost:3000/foo/blablablawill cause Express to:==>
TypeError: Cannot read properties of undefined (reading 'bar')After the uncaught exception,
req.paramsisundefined(among other req parameters, not listed here). Thus, trying to accessbarfromundefinedis also an exception, causing the server to crash and terminate.Looks like Express "clears" some variables in the
reqobject.