> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend Functions Overview

> Write custom backend logic with Deno-powered serverless functions

<div className="dev-docs-banner">
  <div className="dev-docs-banner-content">
    <div className="dev-docs-banner-title">
      You're viewing developer documentation
    </div>

    <div className="dev-docs-banner-text">
      This documentation is for developers working with the Base44 developer
      platform. For information about backend functions in the app editor, see{" "}

      <a href="/Integrations/Using-integrations#activating-backend-functions">
        Using Integrations
      </a>

      .
    </div>
  </div>
</div>

Backend functions let you run custom backend code in a secure, isolated environment. Use functions to implement business logic that shouldn't run in the browser, connect to third-party APIs with protected credentials, process webhooks, or extend your app with custom endpoints.

Backend functions run on [Deno](https://docs.deno.com/runtime/), a modern TypeScript runtime. Call functions from your frontend [using the SDK](/developers/references/sdk/docs/interfaces/functions), which handles authentication automatically. Each function also gets its own HTTP endpoint for webhooks and external integrations.

Functions can also run automatically using [automations](/developers/backend/resources/backend-functions/automations). Schedule functions to run at specific times or trigger them in response to database events like creating, updating, or deleting records.

<Note>Each project supports a maximum of 50 backend functions.</Note>

## Create functions

Create backend functions as TypeScript files in your project's functions directory. By default the functions directory is `base44/functions/`, but you can customize the path in your [project configuration](/developers/backend/overview/project-structure#config-jsonc).

Each function lives in its own subdirectory with an `entry.ts` or `entry.js` file:

<Tree>
  <Tree.Folder name="functions" defaultOpen>
    <Tree.Folder name="<function-name>" defaultOpen>
      <Tree.File name="entry.ts" />
    </Tree.Folder>
  </Tree.Folder>
</Tree>

The CLI uses the directory path relative to the functions root as the function name. For example, `functions/sendWelcomeEmail/entry.ts` creates a function named `sendWelcomeEmail`. You can also nest functions in subdirectories for organization. `functions/email/send/entry.ts` creates a function named `email/send`.

### Adding a configuration file

For advanced needs like custom function names or [automations](/developers/backend/resources/backend-functions/automations), add a `function.jsonc` file:

<Tree>
  <Tree.Folder name="functions" defaultOpen>
    <Tree.Folder name="<function-name>" defaultOpen>
      <Tree.File name="entry.ts" />

      <Tree.File name="function.jsonc" />
    </Tree.Folder>
  </Tree.Folder>
</Tree>

The configuration file defines the function's name and entry point:

```jsonc theme={null}
{
  "name": "sendWelcomeEmail",
  "entry": "entry.ts",
}
```

| Property      | Description                                                                                                                                                                                                   |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`        | Optional. Unique identifier for the function. Used when invoking via SDK or HTTP. Defaults to the directory path relative to the functions root.                                                              |
| `entry`       | The file containing the function code.                                                                                                                                                                        |
| `automations` | Optional. Array of automation configurations to run the function on a schedule or in response to database events. See [Automations](/developers/backend/resources/backend-functions/automations) for details. |

### entry.ts

The code file contains your function logic. Functions must use the `Deno.serve()` wrapper and return `Response` objects:

```typescript theme={null}
import { createClientFromRequest } from "npm:@base44/sdk";

Deno.serve(async (req) => {
  try {
    const base44 = createClientFromRequest(req);
    const user = await base44.auth.me();

    if (!user) {
      return Response.json({ error: "Unauthorized" }, { status: 401 });
    }

    const { name } = await req.json();

    return Response.json({
      message: `Hello, ${name || user.full_name}!`,
    });
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 });
  }
});
```

## Test locally

Run your functions locally with [`base44 dev`](/developers/references/cli/commands/dev) to test changes without deploying. See [Local development](/developers/backend/overview/local-dev/local-development-overview) for details.

## Deploy functions

Deploy functions with [`functions deploy`](/developers/references/cli/commands/functions-deploy) or [`deploy`](/developers/references/cli/commands/deploy) to push all project resources at once. You can deploy specific functions by name with `functions deploy <names...>`, or use `--force` to remove remote functions not found locally.

To download deployed functions to your local project, use [`functions pull`](/developers/references/cli/commands/functions-pull). To see what's currently deployed, use [`functions list`](/developers/references/cli/commands/functions-list).

## Call functions

Call backend functions from your frontend using the SDK, or via HTTP for webhooks and external integrations.

### Via the SDK

Use [`base44.functions.invoke()`](/developers/references/sdk/docs/interfaces/functions) to call functions from your frontend. The SDK handles authentication automatically, passing the current user's credentials to your function.

```javascript theme={null}
import { base44 } from "@/api/base44Client";

const response = await base44.functions.invoke("sendWelcomeEmail", {
  name: "Alice",
});
```

### Via HTTP

Each deployed function gets an HTTP endpoint at:

```
https://<your-app-domain>/functions/<function-name>
```

This is useful for:

* **Webhooks:** Receive callbacks from external services like Stripe or GitHub.
* **External integrations:** Allow other systems to interact with your app.
* **Testing:** Call functions directly with tools like cURL or Postman.

**Example usage**

```bash theme={null}
curl -X POST https://your-app.base44.app/functions/sendWelcomeEmail \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice"}'
```

<Note>
  When calling functions via direct HTTP (like cURL or webhooks), there's no
  authenticated user context. Use `asServiceRole` for all operations in these
  cases.
</Note>

## Use the SDK in functions

Inside your backend functions, you can access your app's data, authentication, and integrations through the Base44 SDK. Use [`createClientFromRequest()`](/developers/references/sdk/docs/functions/createClientFromRequest) to create a client from the incoming request.

The authentication context depends on how the function was called:

* **When called via the SDK from your frontend:** The user's authentication is passed through automatically. You can access the current user with `base44.auth.me()` and perform operations with their permissions. For admin-level operations, use [`asServiceRole`](/developers/references/sdk/docs/functions/createClientFromRequest#asservicerole).

* **When called via direct HTTP (cURL, webhooks, external services):** There's no authenticated user, so use `asServiceRole` for all operations.

## Connect to third-party APIs

Backend functions are one of several ways to [connect to third-party APIs](/developers/references/sdk/getting-started/third-party-apis). They're ideal when you need full control over requests or want to store API keys securely as environment variables. Use [`secrets set`](/developers/references/cli/commands/secrets-set) to configure environment variables from the CLI.

## View logs

During [local development](/developers/backend/overview/local-dev/local-development-overview), function output is printed directly to your terminal without needing the `logs` command.

For deployed functions, view logs with the [`logs`](/developers/references/cli/commands/logs) command. The logs include console output, errors, and timing information. You can filter by function name or time range. If you're using an AI coding agent, the [base44-troubleshooter](/developers/backend/overview/skills#base44-troubleshooter) skill can fetch and analyze these logs automatically.

## TypeScript types

Generate TypeScript types from your function configurations to get type safety and autocomplete for function names in your SDK code. Learn more about [dynamic types](/developers/references/sdk/getting-started/dynamic-types).

## See also

* [Automations](/developers/backend/resources/backend-functions/automations): Schedule functions or trigger them on database events
* [`functions` module](/developers/references/sdk/docs/interfaces/functions): SDK reference for invoking functions
* [`createClientFromRequest`](/developers/references/sdk/docs/functions/createClientFromRequest): Creating a client in backend functions
* [`functions deploy`](/developers/references/cli/commands/functions-deploy): Deploy local functions to Base44
* [`functions pull`](/developers/references/cli/commands/functions-pull): Download deployed functions to your local project
* [`functions list`](/developers/references/cli/commands/functions-list): List all deployed functions
* [`functions delete`](/developers/references/cli/commands/functions-delete): Delete deployed functions
* [`logs`](/developers/references/cli/commands/logs): View function logs
* [`exec`](/developers/references/cli/commands/exec): Test functions in isolation from standalone scripts
