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.
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.
-
Install the CLI and log in. Once per machine.
loginopens your browser to sign in.Terminalbashnpm i -g @naijacloud/cli naijacloud login -
Make a folder and save this in it as hello.ts.
hello.tstsexport default async function handler(req: Request) { const name = process.env.GREETING ?? "world"; return Response.json({ message: `Hello ${name}` }); } -
Deploy it. Run this in the same folder, with your project's name.
Terminalbashnaijacloud 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> -
Call it.
Terminalbashcurl https://<your-project>-fn.naijacloud.app/functions/v1/hello # {"message":"Hello world"} -
Give it a variable. Set
GREETING(the CLI asks for the value), then deploy again so the function picks it up:Terminalbashnaijacloud 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(orindex.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.