'use server'

Directive that marks a function or module as server-only Server Actions.

Since Next 14 (stable) Spec ↗

Syntax

'use server' (top of file, or first line inside an async function)

Returns

directive — Designates Server Action boundaries.

Examples

// File-level: every export becomes a Server Action
'use server'

export async function deleteItem(id: string) {
  await db.items.delete(id)
}
// Inline within a Server Component
export default function Page() {
  async function submit(formData: FormData) {
    'use server'
    await save(formData)
  }
  return <form action={submit}><button>Save</button></form>
}

Notes

Not the same as `'use client'`. `'use server'` exposes async functions as Server Actions that can be invoked from the client over the network. Every exported function in a `'use server'` file must be async. Treat them as public endpoints: validate input and check auth inside.

See also