Home > OS >  expressjs: which options will hang the request when response methods are not called
expressjs: which options will hang the request when response methods are not called

Time:10-05

Which of these below referred codes (options) will hang the user request when response methods are not called from a route handler.

Option 1: app.get('/user', function(req, res, next) { res.redirect('/user/all'); })

Option 2: app.get('/user', function(req, res, next) {})

Option 3: app.get('/user', function(req, res, next) { console.log('handling req'); })

Option 4: app.get('/user', function(req, res, next) { res.send('user data'); })

Option 5: app.get('/user', function(req, res, next) { res.end(); })

CodePudding user response:

options 2,3 because they are not calling any of the res.(methods) for the http request to be closed.

res.redirect(...)
res.send(...)
res.end()

all call the res.end() in their inner implementation. that method will close the http tcp connection with a response to the client.

  • Related