app/server-component.js export default function ServerComponent() {
  async function myAction() {
    'use server'
    // ...
  }
}
With Client Components
If you're using a Server Action inside a Client Component, create your action in a separate file with the "use server" directive at the top of the file. Then, import the Server Action into your Client Component:
app/actions.js 'use server'
 
export async function myAction() {
  // ...
}
app/client-component.js 'use client'
 
import { myAction } from './actions'
 
export default function ClientComponent() {
  return (
    <form action={myAction}>
      <button type="submit">Add to Cart</button>
    </form>
  )
}