You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> info **Note** The `onModuleInit` is optional — if you leave it out, Prisma will connect lazily on its first call to the database. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection. For more info on `enableShutdownHooks`, please see [Issues with `enableShutdownHooks`](#issues-with-enableShutdownHooks)
270
+
266
271
Next, you can write services that you can use to make database calls for the `User` and `Post` models from your Prisma schema.
267
272
268
273
Still inside the `src` directory, create a new file called `user.service.ts` and add the following code to it:
@@ -516,6 +521,25 @@ This controller implements the following routes:
516
521
517
522
-`/post/:id`: Delete a post by its `id`
518
523
524
+
#### Issues with `enableShutdownHooks`
525
+
526
+
Prisma interferes with NestJS `enableShutdownHooks`. Prisma listens for shutdown signals and will call `process.exit()` before your application shutdown hooks fire. To deal with this, you would need to add a listener for Prisma `beforeExit` event.
You can [read more](https://github.com/prisma/prisma/issues/2917#issuecomment-708340112) about Prisma handling of shutdown signal, and `beforeExit` event.
542
+
519
543
#### Summary
520
544
521
545
In this recipe, you learned how to use Prisma along with NestJS to implement a REST API. The controller that implements the routes of the API is calling a `PrismaService` which in turn uses Prisma Client to send queries to a database to fulfill the data needs of incoming requests.
0 commit comments