Creating Functions
Base44 functions are serverless backend functions that run on Deno. They are defined locally in your project and deployed to the Base44 backend.Function Directory
All function definitions must be placed in thebase44/functions/ folder in your project. The simplest function is a folder with an entry.ts or entry.js file inside it.
Example structure:
How to Create a Function
- Create a new directory in
base44/functions/with your function name (use kebab-case) - Create
entry.ts(orentry.js) in that directory - Deploy the function using the CLI
Function Discovery
The CLI discovers functions fromentry.ts or entry.js files. A folder that contains one of those files is a function:
| File | Function name |
|---|---|
base44/functions/process-order/entry.ts | process-order |
base44/functions/orders/process/entry.ts | orders/process |
entry.tsorentry.jsmust be inside a named subfolder, not directly inbase44/functions/- all
*.js,*.ts, and*.jsonfiles under the function folder are included when deploying - function paths with a dot in any path segment are ignored
Entry Point File
Functions run on Deno and must export usingDeno.serve(). Use npm: prefix for npm packages.
Request Object
The function receives a standard DenoRequest object:
req.json()- Parse JSON bodyreq.text()- Get raw text bodyreq.headers- Access request headersreq.method- HTTP method
Response Object
Return usingResponse.json() for JSON responses:
Complete Example
Directory Structure
entry.ts
Using Service Role Access
For admin-level operations, useasServiceRole:
Using Secrets
Access environment variables configured in the app dashboard:Naming Conventions
- Directory name: Use kebab-case (e.g.,
process-order,send-notification) - Function name: Comes from the directory path under
base44/functions/- Valid:
process-order,orders/process,send_notification,myFunction - Invalid:
process.order,send.notification.v2
- Valid:
- Entry file: Use
entry.tsorentry.js
Deploying Functions
After creating your function, deploy it to Base44:Notes
- Functions run on Deno runtime, not Node.js
- Use
npm:prefix for npm packages (e.g.,npm:@base44/sdk) - Use
createClientFromRequest(req)to get a client that inherits the caller’s auth context - Configure secrets via app dashboard for API keys
- Make sure to handle errors gracefully and return appropriate HTTP status codes
Common Mistakes
| Wrong | Correct | Why |
|---|---|---|
base44/functions/myFunction.js (single file) | base44/functions/my-function/entry.ts | Functions must live in a named subdirectory |
base44/functions/entry.ts | base44/functions/my-function/entry.ts | The function name comes from the subdirectory path |
import { ... } from "@base44/sdk" | import { ... } from "npm:@base44/sdk" | Deno requires npm: prefix for npm packages |
MyFunction or myFunction directory | my-function directory | Use kebab-case for directory names |

