0Pricing
Sveltejs Academy · Lesson

The init() Hook

Run one-time server initialization code when the SvelteKit server starts.

What init Does

The init hook runs once when the SvelteKit server starts up, before any request.

Export init

From hooks.server.js.

export async function init() {
  await connectDb();
  console.log("Server ready");
}

All lessons in this course

  1. The handle() Hook: Middleware for Requests
  2. handleError for Server Error Logging
  3. The init() Hook
  4. Sequence() for Composing Hooks
← Back to Sveltejs Academy