title: Node Express specific timeout value per route
body: <p>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.</p>
  
  <p>From what I've read and experienced:</p>
  
  <ul>
  <li><a href="https://nodejs.org/api/http.html#http_server_timeout" rel="noreferrer">the default Node server timeout is 2 minutes</a></li>
  <li><a href="https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback" rel="noreferrer">a Node socket has no timeout by default</a></li>
  <li><a href="https://github.com/expressjs/timeout" rel="noreferrer">there's middleware from Express to handle timeouts</a></li>
  </ul>
  
  <p>However, I'm lost when trying to implement the <a href="https://github.com/expressjs/timeout" rel="noreferrer">connect-timeout</a> middleware for the upload route.</p>
  
  <p><strong>Application setup</strong></p>
  
  <pre><code>const app = express();
  app.use(cors());
  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));
  app.use(passport.initialize());
  
  app.use('/uploads', uploadRoutes);
  app.use(errorHandler);
  
  function errorHandler(err, req, res, next) {
    if (err.code &amp;&amp; err.code === 'ETIMEDOUT') {
      if (!res.headersSent) {
        res
          .status(408)
          .send({
            success: true,
            message: 'Timeout error'
          });
      }
    }
  
    next(err);
  }
  
  const server = app.listen(config.port);
  </code></pre>
  
  <p><strong>Upload route definition</strong></p>
  
  <pre><code>router.route('/:uploadId/upload-files')
    .post(timeout('3m'),
      require('./actions/upload-files').prepareHandler,
      require('./actions/upload-files').uploadHandler(),
      require('./actions/upload-files').responseHandler);
  </code></pre>
  
  <p>However, when uploading the files I do see the error from <code>express-timeout</code> after 3 minutes ONLY in the command line's console. The request is still in progress and no status code of 408 is returned.</p>
  
  <p>After 4 minutes I finally see the 408 status and 'Timeout error' as part of the response object.</p>
  
  <p>For requests to other routes I get the <code>net::ERR_EMPTY_RESPONSE</code> error after  4 minutes.</p>
  
  <p>If I log the value for <code>server.timeout</code>, the value is <code>120000</code> (2 minutes).</p>
  
  <p><strong>My questions</strong></p>
  
  <ul>
  <li>where can the 4 minutes possible come from? Is it because there's a preceding OPTIONS request maybe?</li>
  <li>what's the difference between server &amp; socket timeouts and how to set them properly for a specific route?</li>
  </ul>