Skip to main content

Edge Functions

Run serverless JavaScript functions on NaijaBase infrastructure in Lagos, Nigeria. Functions execute in isolated Docker containers, bill in Naira, and are NDPA 2023 compliant — your code never leaves Nigeria.

What are Edge Functions?​

Edge Functions let you run custom server-side logic without managing infrastructure. Each function:

  • Runs in an isolated node:20-alpine Docker container
  • Executes in Lagos, Nigeria (Rack Centre, Victoria Island)
  • Has a configurable memory limit (128 MB – 1 GB)
  • Has a configurable timeout (10 – 300 seconds)
  • Is billed per invocation in Naira (₦)

Plan Limits​

PlanFunctionsMemoryTimeout
Starter0——
Growth5128 MB10s
Scale20256 MB30s
Business50512 MB60s
Compliance ProUnlimited1 GB300s

Writing a Function​

Functions export a default async handler that receives a request payload and returns a JSON-serialisable value.

export default async function handler(req) {
const { name = 'World' } = req

return {
message: `Hello ${name}! Running in Lagos 🇳🇬`,
timestamp: new Date().toISOString(),
}
}

Supported APIs​

  • All built-in Node.js globals (console, Date, Math, JSON, Buffer, etc.)
  • fetch (Node 20 native)
  • Any npm package bundled into your function code (e.g. via esbuild)

Security Restrictions​

For the security of all tenants, the following are blocked:

PatternReason
child_processPrevents shell access
net / dgramRaw socket access blocked
fs writesRead-only filesystem only
process.exit()Cannot terminate the host
Paths: /etc/, /root/, /srv/System directory access
DATABASE_URL in codePrevents credential leakage

Invoking a Function​

HTTP (public endpoint)​

Every function has a public URL. Invoke it with a POST request and a JSON body. You must include your project API key in the Authorization header.

curl -X POST https://api.naijabase.dev/functions/v1/YOUR_PROJECT_ID/hello \
-H "Authorization: Bearer YOUR_PROJECT_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Ade" }'

Response:

{
"message": "Hello Ade! Running in Lagos 🇳🇬",
"timestamp": "2025-01-15T10:30:00.000Z"
}

JavaScript SDK​

import { createClient } from '@naijabase/js'

const nb = createClient('https://api.naijabase.dev/projects/YOUR_PROJECT_ID', 'YOUR_PROJECT_API_KEY')

const result = await nb.functions.invoke('hello', {
body: { name: 'Ade' },
})

console.log(result.message) // Hello Ade! Running in Lagos 🇳🇬

Creating a Function (Dashboard)​

  1. Open your project → Functions tab
  2. Click Create Function
  3. Fill in:
    • Name — human-readable label (e.g. "Send Welcome Email")
    • Slug — URL-safe identifier (e.g. send-welcome-email)
    • Memory — container RAM limit
    • Timeout — maximum execution time
    • Code — your JavaScript function
  4. Click Create & Deploy

Your function is live immediately. The public URL is shown in the detail view.

Execution Logs​

Every invocation is logged. View logs in the Functions tab → select a function → Logs. Each log entry shows:

  • Execution timestamp (WAT)
  • Trigger type (http or cron)
  • Status (success / error)
  • Duration in milliseconds
  • Memory consumed

Environment Variables​

Store secrets (API keys, tokens) as environment variables on the function. They are injected into the container at runtime and never appear in logs.

In the dashboard: Functions → select function → Code tab → click Edit → expand Environment Variables.

Access in your code:

export default async function handler(req) {
const apiKey = process.env.SENDCHAMP_API_KEY
// use apiKey...
}

Limits and Quotas​

  • Code size: 1 MB maximum
  • Response size: 6 MB maximum
  • Concurrent executions: 10 per project (contact support to increase)
  • Cold start: typically < 500 ms (Docker container spin-up)