useRequestEvent()

Returns the underlying H3 request event during SSR.

Since Nuxt 3.0 Spec ↗

Syntax

const event = useRequestEvent()

Returns

H3Event | undefined — The current request event on the server; undefined on the client.

Examples

<script setup lang="ts">
const event = useRequestEvent()
if (event) {
  event.node.res.setHeader('X-Frame-Options', 'DENY')
}
</script>
// composables/useClientIp.ts
export function useClientIp() {
  const event = useRequestEvent()
  return event
    ? getRequestIP(event, { xForwardedFor: true })
    : undefined
}

Notes

Only available during SSR; returns `undefined` in the browser, so always guard with a truthy check. Gives low-level access to the H3 event for setting response headers, reading the raw request, or using H3 utilities like `getCookie`/`setResponseStatus`.

See also