---
title: "Nitro"
description: "Access the Node SDK in Nitro and manage delivery within a request."
canonical_url: "https://mixpanel-nuxt.vercel.app/integration/nitro"
---
# Nitro

> Access the Node SDK in Nitro and manage delivery within a request.

Call `useMixpanelServer()` in a server route, plugin or utility to access the [Mixpanel Node SDK](https://docs.mixpanel.com/docs/tracking-methods/sdks/nodejs). It is auto-imported in Nitro; an explicit import is also available from `#mixpanel/server`.

For project tokens and SDK options, see [Configuration](https://mixpanel-nuxt.vercel.app/get-started/configuration).

## Request delivery

```ts [server/api/example.post.ts]
import { useMixpanelServer } from '#mixpanel/server'

export default defineEventHandler(async () => {
  const mixpanel = useMixpanelServer()

  await new Promise<void>((resolve, reject) => {
    mixpanel.track('Report generated', {
      distinct_id: 'user-42',
      format: 'csv',
    }, (error) => {
      if (error) reject(error)
      else resolve()
    })
  })

  return { ok: true }
})
```

The Node SDK reports completion through callbacks. Wrapping the callback in a Promise lets the handler wait for delivery.

<warning>

`await mixpanel.track(...)` alone does not wait for the request.

</warning>

The example propagates tracking errors to the route.

## Shared client

The module initializes the SDK on first use and reuses that instance across requests. Supply request-specific data, including `distinct_id`, with each operation.

<warning>

Do not store a request's identity or properties on the shared client.

</warning>

## Delivery in serverless functions

Await the callback-wrapped Promise before returning when the event must finish within the request lifetime.

For background delivery, pass that Promise to `event.waitUntil()` and handle its rejection. The deployment preset must support extending the request lifetime after the response.

Server tracking supports Node and serverless Node. Edge presets are not covered.

See [`useMixpanelServer()`](https://mixpanel-nuxt.vercel.app/api/composables/use-mixpanel-server) for the accessor's return type and availability.


## Sitemap

See the full [sitemap](https://mixpanel-nuxt.vercel.app/sitemap.md) for all pages.
