Reputation: 731
We are progressively migrating our app from the NestJS framework to Express and thought of including NestJS as a module of Express so the migration can be done in small batches. Things seem to be connected but the NestJS seems to be a restart for every request. This is not a bug but a general approach on how to coexist Express & NestJS would be appreciated.
Express + NestJS repo https://gitlab.com/vijaysvj/express-with-nest/-/tree/master/
References:
Upvotes: 2
Views: 1532
Reputation: 70121
What would almost be an undoubtedly better approach would be to pass the current express application to an ExpressAdapter
for Nest, and then run the NestJS server, instead of trying to cram the NestJS server into the Express server. Something like this:
const bootstrap = async () => {
const adapter = new ExpressAdapter(expressApp); // from @nestjs/platform-express
const app = await NestFactory.create(AppModule, adapter);
await app.listen(3000);
}
bootstrap();
Where expressApp
is your already created express application. Doing this will allow all of your express functionality to still exist while you migrate over to NestJS. Just make sure to migrate any error handlers and post-request middleware to the appropriate Nest enhancers (like Filters and Interceptors).
Upvotes: 2