title: Node/Express, How do I modify static files but still have access to req.params?
body: <p>I'm new to node/express, so there's (hopefully) an obvious answer that I'm missing.</p>
  
  <p>There's a middleware for transforming static content: <a href="https://www.npmjs.com/package/connect-static-transform/" rel="nofollow noreferrer">https://www.npmjs.com/package/connect-static-transform/</a>. The transformation function looks like:</p>
  
  <pre><code>transform: function (path, text, send) {
     send(text.toUpperCase(), {'Content-Type': 'text/plain'});
  }
  </code></pre>
  
  <p>So, that's great for transforming the content before serving, but it doesn't let me look at query parameters.</p>
  
  <p>This answer shows how to do it <a href="https://stackoverflow.com/questions/9896628/connect-or-express-middleware-to-modify-the-response-body">Connect or Express middleware to modify the response.body</a>:</p>
  
  <pre><code>function modify(req, res, next){
     res.body = res.body + "modified";
     next();
  }
  </code></pre>
  
  <p>But I can't figure out how to get it to run with static file content. When I run it <code>res.body</code> is undefined.</p>
  
  <p>Is there some way to get a middleware to run <em>after</em> <code>express.static</code>?</p>
  
  <p>My use case is that I want to serve files from disk making a small substitution of some text based on the value of a query parameter. This would be easy with server-side templating, like Flask. But I want the user to be able to do a simple npm-install and start up a tiny server to do this. Since I'm new to node and express, I wanted to save myself the bother of reading the url, locating the file on disk and reading it. But it's becoming clear that I wasted much more time trying this approach.</p>