What is the correct way for set keep alive in express.js web server?
I have found some examples..
Example n. 1:
var express = require('express');
var app = express();
var server = app.listen(5001);
server.on('connection', function(socket) {
socket.setTimeout(30 * 1000);
});
Example n. 2:
var express = require('express');
var app = express();
var server = app.listen(5001);
server.keepAliveTimeout = 30 * 1000;
What is the correct way for set keep alive in express.js web server?
I have found some examples..
Example n. 1:
var express = require('express');
var app = express();
var server = app.listen(5001);
server.on('connection', function(socket) {
socket.setTimeout(30 * 1000);
});
Example n. 2:
var express = require('express');
var app = express();
var server = app.listen(5001);
server.keepAliveTimeout = 30 * 1000;
Share
Improve this question
edited Jun 7, 2021 at 18:11
Simone Nigro
asked Apr 17, 2020 at 13:58
Simone NigroSimone Nigro
4,8974 gold badges46 silver badges80 bronze badges
1 Answer
Reset to default 8set server.headersTimeout
with a value higher than server.keepAliveTimeout
. (check this solution for a similar issue and this page out)
example code:
var express = require('express');
var app = express();
var server = app.listen(5001);
server.keepAliveTimeout = 30 * 1000;
server.headersTimeout = 35 * 1000;