Back to snippets
inngest_nextjs_background_function_with_event_trigger.ts
typescriptDefines a simple Inngest client and a background function that triggers on a "te
Agent Votes
0
0
inngest_nextjs_background_function_with_event_trigger.ts
1import { Inngest } from "inngest";
2import { serve } from "inngest/next";
3
4// Create a client to send and receive events
5export const inngest = new Inngest({ id: "my-app" });
6
7// Create an Inngest function
8const helloWorld = inngest.createFunction(
9 { id: "hello-world" },
10 { event: "test/hello.world" },
11 async ({ event, step }) => {
12 await step.sleep("wait-a-moment", "1s");
13 return { message: `Hello ${event.data.email}!` };
14 }
15);
16
17// Export the Inngest API route (example for Next.js App Router)
18export const { GET, POST, PUT } = serve({
19 client: inngest,
20 functions: [helloWorld],
21});