user1584421
user1584421

Reputation: 3863

Node.js Using setKeepAlive() with express framework

I want to use socket.setKeepAlive() in my application.

This is an example of using this function:

var net  = require('net');
var server = net.createServer(function(socket){
    socket.setKeepAlive(true,60000);

And another proper way to use this function:

var socket = net.connect(opts, function(){
    // 'connect' listener
    socket.setKeepAlive(true, 5000);
    socket.write("hello");
});

Since all this options use vanilla Node.js, how can i use this function with the express framework?

In express, i do not include the net module. Instead, i use this:

var express    = require('express');
var app        = express();

Upvotes: 2

Views: 709

Answers (1)

danday74
danday74

Reputation: 57185

Based on this article:

https://github.com/expressjs/express/issues/3556

You could try using this express middleware:

var express = require('express')
var app = express()

app.use(function (req, res, next) {
  req.socket.setKeepAlive()
  next()
})

Upvotes: 1

Related Questions