Naijacloud
Docs

Functions overview

A function is one file, or a folder with an entry file, that answers HTTPS requests. No repository, framework or port. Deploy it from the CLI and it gets its own URL, reading the variables you give your project's functions.

4 min read

Functions suit the small pieces of backend code a frontend needs: a Paystack webhook, a call to an AI API with a secret key, sending an email. They are like Supabase Edge Functions, and most Supabase functions copy over as they are.

This section covers writing a function, worked examples, secrets, the commands to deploy, read logs and delete, moving from Supabase, and limits and pricing.

Make your first function

You need a Naijacloud project to put it in. Any project works, including one on the Free tier. If you don't have one, create it from Projects → New project in the dashboard.

  1. Install the CLI and log in. Once per machine. login opens your browser to sign in.

    Terminal
    bash
    npm i -g @naijacloud/cli naijacloud login
  2. Make a folder and save this in it as hello.ts.

    hello.ts
    ts
    export default async function handler(req: Request) { const name = process.env.GREETING ?? "world"; return Response.json({ message: `Hello ${name}` }); }
  3. Deploy it. Run this in the same folder, with your project's name.

    Terminal
    bash
    naijacloud functions deploy hello --project <your-project>

    The CLI prints each step, then the URL:

    Code
    ✓ Logged in as you@example.com ✓ Found hello.ts (1 file, 0.2 KB) ✓ Bundled (0.3 KB) ✓ Uploaded version 1 ✓ Live in eu-west https://<your-project>-fn.naijacloud.app/functions/v1/hello Next: naijacloud functions logs hello --project <your-project>
  4. Call it.

    Terminal
    bash
    curl https://<your-project>-fn.naijacloud.app/functions/v1/hello # {"message":"Hello world"}
  5. Give it a variable. Set GREETING (the CLI asks for the value), then deploy again so the function picks it up:

    Terminal
    bash
    naijacloud env set GREETING --service functions-runtime --project <your-project> naijacloud functions deploy hello --project <your-project>

    The call now returns your value, for example {"message":"Hello Lagos"}.

Always copy the URL the CLI or the dashboard shows rather than building it yourself.

The CLI is naijacloud, or njc for short. Every command here works with either.

From the dashboard

In a project, choose New service → Function. It shows the same steps with your project's name filled in, and the page updates by itself when the first deploy lands. Code is deployed from the CLI; there is no code editor in the dashboard yet.

Once a project has a function, a Functions section appears on the project page, listing each function with its calls and errors over the last 24 hours. Open one to see:

  • Overview: the URL, the live version, the variables it can read (names only, never values) and its limits.
  • Logs: one entry per call, with the lines your code printed.
  • Settings: deleting the function.

What happens when you deploy

  • The CLI zips your file or folder and uploads it. A single file is uploaded as index.ts (or index.js).
  • Naijacloud installs any npm dependencies and builds it. An import that can't be found fails the build here, before any call reaches it.
  • If the build fails, the previous version keeps serving and the CLI shows the build log. A broken deploy never takes a working function down.
  • All the functions in one environment of a project run in one shared runtime, a service named functions-runtime. It is created with your first function and removed with your last one.