Update Jan 2025
@Matthias Mertens pointed me in the right direction in the comments of another answer that hooks.server.ts
only runs on the first request in dev mode, but will run at startup in prod. Also, there is now an init()
for anyone coming here in 2025
In hooks.server.ts
:
import type { ServerInit } from '@sveltejs/kit';
import * as db from '$lib/db';
export const init: ServerInit = async () => {
await db.connect()
};