title: How to emulate traffic in express.js
body: <p>I have a node express server responding to http traffic:</p>
  
  <pre><code>const http = require("http");
  const express = require("express");
  const app = express();
  const server = http.createServer(app);
  app.use(function(req,res,next){
    console.log(`logging: req: ${util.inspect(req)}`);
    next();
  });
  </code></pre>
  
  <p>and all that works fine. I'd like to have a program on my node server inject emulated http traffic into the express stack, without a network connection. I can't just magic up a <code>(req,res)</code> pair and call a middleware function like the one in <code>app.use</code> above, because I don't have a <code>next</code> to give it, and my <code>req</code> and <code>res</code> will not be the ones <code>next</code> passes on to the next middleware in the stack.</p>
  
  <p><strong>Edit</strong>: What I actually have is a websocket connection sending data packets of a different format, different data contents from http traffic that can also carry the same information. I can take those websocket packets and build from those a request that is in the same format that the http traffic uses. I would like to pass that transformed request through the express http middleware stack and have it processed in the same way. Going all the way back to create an http request having just dealt with a ws request seems a bit far.</p>
  
  <p>What's the simplest way to emulate some traffic, please? Can I call a function on <code>app</code>? Call some express middleware, or write a middleware of my own to inject traffic? Call a function on <code>server</code>?</p>
  
  <p>Thanks!</p>