How to Use NestJS as SSR Server for Angular v20 | POC

18.07.2025 - 15:44

Read on dev.to

Did you ever think about using nestjs as your SSR Server for angular v20 ?
It's actually pretty easy to set this up as a POC.

First of all we need to install a few dependencies to our angular application.

Those are:
`

"@nestjs/serve-static": "^5.0.3",
"@nestjs/cli": "^11.0.7",
"@nestjs/common": "^11.1.5",
"@nestjs/core": "^11.1.5",
"@nestjs/platform-express": "^11.1.5",
"@nestjs/schematics": "^11.0.5",
"@types/node": "^20.19.8",
"reflect-metadata": "^0.2.2",
Enter fullscreen mode Exit fullscreen mode

`

After that we need to define a middleware to use the AngularNodeAppEngine within our NestJS server.

After that we need to create our AppModule where we register the Middleware and import the ServerStaticModule for static content serving.

This will look like this:

That's basically all we need.
Our server.ts within the Angular App will look like this:

Now if you run npm run start and have SSR enabled you will see that the NestJS server starts up perfectly fine.

Please note that this is just a simple POC and needs some tweaking as for example sometimes when the app is reloading the server is not shutting down completly or npm run build doesn't work at this time.

But i will try to improve my POC github repo to fix this issues.

You can find the minimal POC repo here:
https://github.com/xsip/ng-nest-ssr

Hopefully this helped you in some way.
Have a nice day :)