# setServerCookie

### `setServerCookie` Function

The `setServerCookie` function is used to **create or update a first-party cookie on the server side**. This is useful for scenarios where cookie persistence is handled via the server response rather than directly in the browser.

#### How It Works

* The function **stores** the cookie definition **temporarily** on the client.
* Once a **HTTP stream is sent to the JENTIS environment**, the cookie is transmitted to the server.
* JENTIS then returns the cookie in the HTTP response, setting it as a **server-side first-party cookie**.

***

#### Function Signature

```ts
this.setServerCookie(config: {
  name: string;   // required
  value: string;  // required
  exdays?: number; // optional, in seconds
}): void
```

#### Parameters

* **`name`** (`string`, required):\
  The name of the server-side cookie.
* **`value`** (`string`, required):\
  The value to be stored in the cookie.
* **`exdays`** (`number`, optional):\
  The **duration of the cookie in seconds**.\
  This corresponds to the `Max-Age` attribute of the HTTP cookie.\
  \&#xNAN;*(Note: This differs from `setCookie`, where the value represents days or minutes.)*

***

#### Return Value

* **Type:** `void`\
  This function does not return a value.

***

#### Example

**Set a server-side cookie with a 10-day expiration**

```js
function() {
  this.setServerCookie({
    name: "Cookie-Name",
    value: "Cookie-Value",
    exdays: 10 * 24 * 60 * 60 // 10 days in seconds
  });
  return "";
}
```

***

#### ⚠️ Important Notes

* **`exdays` must be an integer representing seconds.**
* This differs from the `setCookie` function, where `exdays` can accept a JSON format for minutes or a number representing days.
* The cookie will not be available immediately; it will be set only **after a data stream is sent to JENTIS**.

***

Use `setServerCookie` when you require persistent cookies that are issued and managed via the server, providing improved reliability across domains and better control over secure contexts.
