2

How do I run code when my Sveltekit application is exiting?

I have a hooks.server.ts file that initializes a DB connection when the app starts. If my server shuts off, how do I close the connection?

Thanks

Peyton Hanel
  • 374
  • 1
  • 3
  • 13
  • I don't think there is such hook available yet. Maybe you can use the generic Node.js atexit handler https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits – Mikko Ohtamaa Dec 26 '22 at 08:46
  • 2
    Also any TCP/IP connections will be automatically terminated when the underlying process dies by the operating system. – Mikko Ohtamaa Dec 26 '22 at 08:47

0 Answers0