Skip to content

NextJS Integration Example ​

Easiest way to use LambdaQueue in your NextJS application is to use our serverless SDK. It's with any hosting provider, but has some options auto-detection for Vercel and Netlify.

Start by installing the package:

bash
npm add @dayone-labs/lambda-queue-serverless

INFO

We take care to make our client libraries as slim as possible. Don't be afraid of dependency hell when installing our SDKs. We have exactly 0 dependencies.

Below you can find a minimal code example on how to push and handle queue items using NextJS app router.

Code example ​

Here's a small sample application that pushes arbitrary data to queue using NextJS SDK.

ts
import { queue } from '@dayone-labs/lambda-queue-serverless'

type Payload = {
  name: string
  age: number
}
export const welcomeQueue = queue(
  '/lq/queue', //Pass route that it will be served at❗
  async (job: Payload) => {
    console.log(`Hi ${job.name}, you are ${job.age} years old!`)
  }
)
ts
import { welcomeQueue } from './welcome-queue'

//Queue is a route handler, just expose it as POST
export const POST = welcomeQueue
//Remember to expose HEAD so we can validate endpoint
export const HEAD = welcomeQueue
tsx
'use client'
import { pushToQueue } from './actions'

export const Page = () => {
  return (
    <div>
      <button onClick={() => pushToQueue()}>Press to Push!</button>
    </div>
  )
}

export default Page
ts
'use server'
import { welcomeQueue } from './welcome-queue'

export const pushToQueue = async () => {
  await welcomeQueue.push({ name: 'John Doe', age: 30 })
}

All examples are licensed under MIT. You can use them for free in your projects.