JAVASCRIPTWarningFramework ErrorJune 16, 2026

Framework Error

Express Router middleware function does not return a response

What This Error Means

This error occurs when a middleware function in an Express.js router does not return a response, causing the request to hang indefinitely.

Why It Happens

Middleware functions in Express.js should return a response, either by sending a response back to the client, calling `next()` to pass control to the next middleware function, or by throwing an error. If a middleware function does not return a response, the request will hang, leading to this error.

How to Fix It

  1. 1To fix this error, ensure that all middleware functions in your Express.js router return a response. This can be done by sending a response back to the client, calling `next()` to pass control to the next middleware function, or by throwing an error. For example:
  2. 2// Before (broken code)
  3. 3app.get('/', (req, res) => {
  4. 4 // Code that does not return a response
  5. 5 res.status(500).send('Internal Server Error')
  6. 6});
  7. 7// After (fixed code)
  8. 8app.get('/', (req, res) => {
  9. 9 // Code that returns a response
  10. 10 res.status(200).send('Hello World')
  11. 11});

Example Code Solution

❌ Before (problematic code)
JavaScript
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  // Code that does not return a response
  // res.status(200).send('Hello World');
  // Calling next() without a response
  // res.status(500).send('Internal Server Error');
  // Instead, this middleware function just returns
  // This is the problematic middleware function
});
✅ After (fixed code)
JavaScript
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  // Code that returns a response
  res.status(200).send('Hello World')
});

Fix for Express Router middleware function does not return a response

Related JAVASCRIPT Errors

Related JAVASCRIPT Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error