title: Running two NestJS applications in the same process
body: <p>I've been working with <a href="https://expressjs.com/" rel="nofollow noreferrer">Express</a> for a couple of years now and recently got introduced to NestJS. I decided to experiment and write an application on this, as it seemed to me, interesting framework.</p>
  <p>I want my application to be able to handle the following routes:</p>
  <ul>
  <li>General routes
  <code>/policy</code>, <code>/docs</code></li>
  <li>API routes (with versioning)
  <code>/api/v1/users</code>, <code>/api/v1/chats</code></li>
  </ul>
  <p>In Express, this is very easy to do, but as I understand it, in NestJS everything is different. As I understand from the documentation, in NestJS you cannot set the path prefix for the entire module. You can only set a global prefix for the entire application.</p>
  <p>The documentation also talked about the <a href="https://docs.nestjs.com/recipes/router-module" rel="nofollow noreferrer">RouterModule</a>. But I didn’t like it, because it won’t be possible to enable versioning specifically for routes /api and the use of RouterModule itself is very inconvenient. As the application grows, using the RouterModule becomes a pain.</p>
  <p>Then I tried to convert the application to a <a href="https://docs.nestjs.com/cli/monorepo#monorepo-mode" rel="nofollow noreferrer">monorepository</a>. It seems to be possible to achieve the desired functionality, but it seems inconvenient for me to run each part of the application separately. Perhaps it would be worth using <a href="https://www.npmjs.com/package/concurrently" rel="nofollow noreferrer">concurrently</a>, but in my opinion, this is also not the best option.</p>
  <p>As a result, I came to the following solution.
  The structure of my project at the moment looks like this:</p>
  <p><a href="https://i.stack.imgur.com/bbOoV.png" rel="nofollow noreferrer">project structure</a></p>
  <p>The api directory will contain all modules related to the api (it will process <code>/api/v1/...</code> routes), and everything else will be in the core (it will process <code>/docs</code>, <code>/policy</code> routes, etc.).</p>
  <p>In fact, everything is the same as when creating a <a href="https://docs.nestjs.com/cli/monorepo#monorepo-mode" rel="nofollow noreferrer">monorepository</a>, but I decided to run all this from a single main.ts</p>
  <p><a href="https://i.stack.imgur.com/QXkal.png" rel="nofollow noreferrer">main.ts</a></p>
  <p>And I have a question, what are the pitfalls of this solution? Will it affect performance? Are there any better options for solving my problem?</p>