DEV Community

Discussion on: Build an API Gateway with NestJs in 10 minutes

Collapse
 
ayushpratap2494 profile image
Ayush Pratap

My question is can we implement both express application and microservice app in the same NEST.JS application? is it possible as I am handling my API Gateway elsewhere using something different! I want my NEST application to listen to outside HTTP requests and also listen to events emitted by other microservices,
Please suggest on it as I want both, I want my microservice to listen to outside HTTP requests also and also able to communicate with other services through ASYNC Communication like REDIS or KAFKA RABBIT MQ??

Collapse
 
danmt profile image
Daniel Marin

Hi Ayush, thanks for taking the time to go through it.

In theory, you can have an HTTP service AND a microservice inside the same project, in NestJs there's a main.ts file that works as an entry point, that's where you usually start the app (whether it's an express HTTP server or a microservice), you can modify the main.ts file so it runs both.

Now, my recommendation is to have 2 NestJs applications:

  • Microservice (Let's call it MS-1)
  • HTTP server using express that registers MS-1. (Like I did for the API Gateway of the article)

This way you can "send stuff" to your Microservice using an HTTP Service. Is there a practical reason you can't have the two services?