If you are developing a web app with Nest.js as the backend. And now, you want to deploy your whole app into a single server. Then you may run into a problem of serving static assets. Especially if your frontend is a SPA. Fear not, there are multiple ways to achieve this, so how to serve static files with NestJS?

In short, we achieve this by using the express.static method inside our Nest App. And pass the assets folder to our method params.

Serve Static Files with NestJS

Serving the static files is straightforward. We just have to use express which comes out of the box with Nest, inside our main.ts file where we initialize our app:

#NestJS #Express.js #Javascript #Nest.js #Node.js

How to serve static files with NestJS
3.20 GEEK