Home
Support Forums

Deployment procedure for NestJS

Hello,
I am a beginner and I would like to upload a NestJS project.
I can’t find any information on google that’s why I’m turning to you. I think that might interest a lot of people.
with you a procedure?

thank you

NestJS seems to be more like a server-side rendering solution and Netlify can not host such projects. Netlify can only serve static HTML, CSS, JS, assets. However, Documentation | NestJS - A progressive Node.js framework shows that, there might be a possibility of static HTML being exported by NestJS. If that’s true, you can simple setup a repo, connect it to Netlify, and it would be done.

I wouldn’t describe it as a server-side rendering solution. Nest.js application can be deployed to netlify lambda. See docs here: Documentation | NestJS - A progressive Node.js framework

Doesn’t that make it server-side rendering? It is using a code on a server to render a page on the fly.

But anyways, I am not a NestJS expert or anything, I had said so only from the initial impression - the ones I got by looking at the home page. This is what it said:

So yeah, I had not dug deep into the docs other than what I had linked. If it’s possible, I stand corrected. Thank you.

1 Like

More for building an API - the A in JAM :slight_smile:

I am not affiliated with nest, just someone else trying to get this working. The example in their docs I linked didn’t actually work but changing to use serverless-http seems to have done the trick for me

Here is my main.js in case that is useful for someone else

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import serverless = require('serverless-http');

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const globalPrefix = '.netlify/functions/main';
  app.setGlobalPrefix(globalPrefix);
  await app.init();

  const expressApp = app.getHttpAdapter().getInstance();
  return serverless(expressApp)
}

let server;
export const handler = async (event, context, callback) => {
  server = server ?? (await bootstrap());
  return server(event, context, callback);
};

A quick look at the documentation link you provided @spacem I see

A cold start is the first time your code has been executed in a while … This process adds significant latency depending on several factors

Remember that functions have a 10 second execution limit so will always run from a cold start. This is not the most effective way to serve a site.

After downloading and building the example static site NestJS offers @duke it doesn’t include an index.html which is the default file for serving on Netlify.