最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js: Express.js set keep-alive - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

set 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;
发布评论

评论列表(0)

  1. 暂无评论