I\'m developing a Node v4.2.4 application using Express v4.13.4. Now I would like to increase the timeout time for a specific upload route.
From what I\'ve read and
I've solved it using the following route configuration:
'use strict';
const ms = require('ms');
const express = require('express');
const router = express.Router();
router.route('/upload-files')
.post(
setConnectionTimeout('12h'),
require('./actions/upload-files').responseHandler
);
function setConnectionTimeout(time) {
var delay = typeof time === 'string'
? ms(time)
: Number(time || 5000);
return function (req, res, next) {
res.connection.setTimeout(delay);
next();
}
}
exports.router = router;
Where the key logic is the following middleware:
function (req, res, next) {
res.connection.setTimeout(delay);
next();
}
I hope this reference will come in handy for others.