Skip to content
v2.7

Functions with the CLI

init function with the Node 22 starter, run function in Docker with the production environment, push, and execution.

In an empty folder (or at the root of your repository), link the folder to a project:

Terminal window
owbase init project

The 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.
Terminal window
owbase init function --name orders --function-id orders

Nothing 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 database

Since 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.

Terminal window
owbase run function --function-id orders

Requires 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_* and OWBASE_VERSION variables and the x-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-reload turns this off.
  • Variables: those in the .env file of the function folder apply; with --with-variables, the function’s variables on the server are included underneath (.env wins on a repeated name).
  • --user-id <ID>: executes as that user (the x-owbase-user-id header and their JWT in x-owbase-user-jwt).
Terminal window
owbase push function --function-id orders

The 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 the functions/orders/.env file, 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.

Terminal window
owbase functions create-execution --function-id orders --path / --method GET

The 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.

A function created in the console comes into the folder with:

Terminal window
owbase pull function --function-id orders

The 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.

Was this page helpful?