Skip to content

Commit 9228482

Browse files
jharrellJolg42
andauthored
Update NestJS examples to not use beforeExit (#4932)
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
1 parent 669432c commit 9228482

4 files changed

Lines changed: 4 additions & 12 deletions

File tree

typescript/graphql-nestjs/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppModule } from './app.module'
33

44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule)
6+
app.enableShutdownHooks()
67
await app.listen(3000, () => {
78
console.log(`
89
🚀 Server ready at: http://localhost:3000/graphql

typescript/graphql-nestjs/src/prisma.service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { PrismaClient } from '@prisma/client'
44
@Injectable()
55
export class PrismaService extends PrismaClient implements OnModuleInit {
66
async onModuleInit() {
7+
// Note: this is optional
78
await this.$connect()
89
}
9-
10-
async enableShutdownHooks(app: INestApplication) {
11-
this.$on('beforeExit', async () => {
12-
await app.close()
13-
})
14-
}
1510
}

typescript/rest-nestjs/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppModule } from './app.module'
33

44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule)
6+
app.enableShutdownHooks()
67
await app.listen(3000)
78
}
89
bootstrap()

typescript/rest-nestjs/src/prisma.service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { PrismaClient } from '@prisma/client'
44
@Injectable()
55
export class PrismaService extends PrismaClient implements OnModuleInit {
66
async onModuleInit() {
7+
// Note: this is optional
78
await this.$connect()
89
}
9-
10-
async enableShutdownHooks(app: INestApplication) {
11-
this.$on('beforeExit', async () => {
12-
await app.close()
13-
})
14-
}
1510
}

0 commit comments

Comments
 (0)