Functions with the CLI
init function with the Node 22 starter, run function in Docker with the production environment, push, and execution.
Project
Section titled “Project”In an empty folder (or at the root of your repository), link the folder to a project:
owbase init projectThe CLI asks for the organization and the project (or creates a new one) and writes owbase.json. Without prompts: owbase init project --organization-id <ORGANIZATION_ID> --project-id <PROJECT_ID>. owbase.json describes the project (functions, sites, tables, buckets) and goes into Git along with the code.
In a folder that is already linked:
- relinking the same project only updates the name and the organization in
owbase.json, without deleting anything; - linking to a different project replaces the whole
owbase.json(functions, sites, tables, buckets). If it has resources, the CLI asks first; without a terminal (script or CI), it refuses and asks for--force.
Create the function
Section titled “Create the function”owbase init function --name orders --function-id ordersNothing goes to the server yet: the CLI creates functions/orders/ with the Node 22 starter and adds the function to owbase.json (entrypoint src/main.js, build command npm install, execution open to anyone, and the execution key with no scopes). To use Node 24, change "runtime": "node-22" to "node-24" in owbase.json before the push. The starter includes:
functions/orders/├── package.json "type": "module" and the @owbase/node dependency├── .gitignore node_modules/ and .env├── README.md└── src/ └── main.js responds { ok: true } at /; commented examples of listing users and writing to the databaseSince anyone can execute the function, the starter exposes nothing from the project. To enable one of the examples in src/main.js, give the execution key the scope it mentions (users.read, rows.write) in Settings → Scopes and check who calls it: the users example requires an authenticated user (x-owbase-user-id) and does not return the email.
What the code receives (req, res, variables, and headers) is in What the code receives.
Run on your machine
Section titled “Run on your machine”owbase run function --function-id ordersRequires Docker to be running. The CLI builds and starts the function on the official image of the function’s runtime (the one in owbase.json), the same one used in production, and shows the address (http://localhost:3000/, or the first free port up to 3100).
- Same environment as production: the
OWBASE_FUNCTION_*andOWBASE_VERSIONvariables and thex-owbase-*headers (with a real execution key, valid in the project) have the same names as in production. Only the country and continent headers don’t exist locally. --port 3999: fixed port.- Reload: when you save a file, the function restarts on its own;
--no-reloadturns this off. - Variables: those in the
.envfile of the function folder apply; with--with-variables, the function’s variables on the server are included underneath (.envwins on a repeated name). --user-id <ID>: executes as that user (thex-owbase-user-idheader and their JWT inx-owbase-user-jwt).
Publish
Section titled “Publish”owbase push function --function-id ordersThe push creates the function on the server (or updates its settings), uploads the folder as a deployment, and waits for the build to finish, showing the log. When the deployment is ready, it goes live. The first time, the function gets the address https://orders.fn.owbase.dev (the ID becomes the name; if the ID is not valid as an address name or the name is already in use, the CLI warns you and you pick another in the console).
--force: asks nothing (for scripts and CI).--with-variables: also uploads the variables from thefunctions/orders/.envfile, which replace those of the function on the server.--async: does not wait for the build.
The package follows the rules in Package and upload the code: node_modules/ is left out and the build reinstalls the dependencies.
Execute
Section titled “Execute”owbase functions create-execution --function-id orders --path / --method GETThe response includes the status, the HTTP code, and the body returned by the function. Execution logs and errors: owbase functions list-executions --function-id orders.
Pull from the server
Section titled “Pull from the server”A function created in the console comes into the folder with:
owbase pull function --function-id ordersThe CLI writes the configuration to owbase.json and downloads the code of the latest deployment to functions/<name>/. Without --function-id, it asks which functions to pull. --no-code pulls only the configuration. The file’s fields and what the push does with them are in The owbase.json file.