If you read this article you probably have a little knowledge about these two frameworks, if not I would recommend you first to take a look at these, they have very good documentation on their websites.

Storytime

So apparently I started a little Github repository where I created some web-app boilerplates and I wanted a server-side rendering solution as well. So while I was sinking in the deeps of the monorepo magic world🎩, I faced a question regarding Next.js and NestJS. Do I really need two node servers?🤔 One to render the react application and one for the backend APIs? **NO! **So here came the idea to let’s just merge these two.

Next.js is amazing!

The guys at Next.js already thought about this, they have a description on their website regarding how can you use a custom server, so from here my job becomes 100% easier.

But there’s a catch, nothing comes without a price. The price that we will lose the Automatic Static Optimizationbut I’m okay with it. In my projects, almost every page has “blocking data requirements”, so it’s not a big drawback in my situation.

Integrating with NestJS

In NestJS we wrap up controllers and services in modules, so in my case, I think the best option is to create a module which purpose is only to serve the UI side, so basically to render our react pages.

Let’s call this module View Module, and it will contain the View Controller(route handling), View Service(providing the next render).

#javascript #next #nest #react #web-development

How to Render Next.js with NestJS
23.70 GEEK