title: Nodejs Express how to write middleware to handle all response
body: <p>In node JS Express, we can write middlewares to intercept requests to either</p>
  
  <ol>
  <li>Call the next middleware in the chain by invoking <code>next</code></li>
  <li>End the chain by calling <code>res.send</code> or similar functions provided by <code>res</code></li>
  </ol>
  
  <p>That means, everytime we want to end a request and send a response in a particular middleware, we have to add (at least) the below snippet.</p>
  
  <pre><code>res.send();
  </code></pre>
  
  <p>Are there ways to write a response frame middleware like this:</p>
  
  <pre><code>responseFrame = (res,req,responseData) =&gt; {
      res.send(responseData);
  }
  </code></pre>
  
  <p>and insinde <code>route.js</code>, use this middleware on all path </p>
  
  <pre><code>app.use(responseFrame);
  </code></pre>
  
  <p>Then, we simply have to end any middleware with <code>next()</code>, as long as we define the correct routes, Express will take care of sending the response (if the next middleware is the <code>responseFrame</code>)</p>