title: Dividing express routes among Node JS Clusters
body: <p>I have a large set of routes in a Node JS application I'm trying to scale to multiple CPU cores (via NodeJS clusters).</p>
  
  <p>The plan I had in mind was to have different workers handling a different set of express.js routes. For example:</p>
  
  <pre><code>/api/ requests handled by WorkerA
  /admin/ handled by WorkerB
  /blog/ handled by WorkerC
  etc
  </code></pre>
  
  <p>Simply using a conditional with the worker ID is not sufficient, since requests can still land at the wrong worker. Also, the processes all run on the same port, so I can't just match &amp; proxy_pass on the URL from inside nginx.</p>
  
  <p>At this point, I'm thinking about swapping out the cluster routing (from master to worker) to match on the URL and route to the correct worker instead of just using the built-in round-robin approach. But this seems a bit hacky and I'm wondering if anyone else has solved this, or might have any other idea.</p>