title: Whats the best practise to register a express middelware?
body: <p>I am currently in a situation where I need to create a small npm package that delivers an express middelware. The goal is that this middelware registers an Endpoint and delivers some data to a client. Normally I would just write my middelware and the consumer then uses it in the following way:</p>
  
  <pre><code>expressApp.use('/mypath', myMiddelware)
  </code></pre>
  
  <p>But I will also deliver an Angular Module that will call this endpoint. Therefore I need to ensure that the endpoints match. With the code above the consumer of my middelware is in control of the path. But I want to achieve that my middelware is control of the path. Therefore I choosed the following approach:</p>
  
  <p>My middelware</p>
  
  <pre><code>const myMiddelware = function(res, req, next){
    if(req.path === '/mypath'){
      res.send('some data')
    }
  }
  </code></pre>
  
  <p>With this approach the user then consumes the middelware in the following way:</p>
  
  <pre><code>expressApp.use(myMiddelware)
  </code></pre>
  
  <p>I searched a lot on the net and did not found an example that uses my approach. I also see the downside of my approach. My middelware will be called on all requests which leads to unnecessary checks. </p>
  
  <p>Has anyone a good solution for this problem?</p>