Skip to main content

Standalone application

If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and Necord does not require Express for work. So if you you don't need a web server, you can remove Express.

To do this, change the bootstrap function in the main.ts file of your project on something like that:

src/main.ts
import { NestFactory } from '@nestjs/core';

async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule);
}

bootstrap();

This initializes Nest as a standalone application (without any network listeners).

All that remains is to remove unused dependencies:

npm un @nestjs/platform-express @types/express
caution

But when you run standalone application you can't use global enhancers due to the fact that they are not registered in the application context. While issue not resolved, you can use local enhancers instead or start your application via app.init() method.