Getting Started
  • Introduction
  • Installation
  • About
Core Concepts
  • Routing System
  • Page Functions
  • Data Fetching
  • Server Components
  • Client Components
  • Server Functions
  • Advanced
Features
  • Dynamic & Query Parameters
  • Navigation
  • Styles & CSS
  • Assets
  • Favicons
Configuration
  • Environment Variables
  • Import Aliases
  • Ejecting
  • Deployment
Dinou logoDinou
docs
npmGitHub

Server Functions

Learn how to define and use Server Functions in Dinou.

Overview

Server Functions in Dinou are functions executed on the server. To define one, use the "use server"; directive at the top of the file where the function is declared.

Server Functions can be invoked from both Server Components and Client Components, and they can even return Client Components.

Example

"use server";

export async function doSomething(myParam, { req, res }) {
  // Access Express request and response objects
  console.log(req.cookies);
  res.clearCookie("jwt", {
    httpOnly: true,
    secure: true,
  });

  // Perform server-side logic
  return `Received: ${myParam}`;
}

In the example above, the doSomething function is a Server Function. It should be called only with myParam as its argument. The additional { req, res } parameter is automatically provided by Dinou as the last argument.

On This Page

Overview