export default async function handler(
request: Request
): Promise<Response> {
const url = new URL(request.url);
const city = request.headers.get('cf-ipcountry');
const start = performance.now();
const data = await fetch(`https://api.nodesail.app/${city}`)
.then(r => r.json());
const elapsed = performance.now() - start;
return new Response(JSON.stringify({
region: city,
data,
duration_ms: elapsed.toFixed(2)
}), {
headers: { 'Content-Type': 'application/json' }
});
}Write the function.
Forget the server.
No provisioning, no capacity planning, no patches. Your code runs at the edge, scales from zero to millions, and costs nothing when idle.
From code to production in three steps
There is genuinely no infrastructure work involved.
01
Write a function
A function is just a handler — receives a request, returns a response. Write it in Node.js, Python, Go, or any supported runtime. No scaffolding.
export default function handler(req, res) {
const name = req.query.name ?? 'world';
res.json({ message: `Hello, ${name}!` });
}02
Push to deploy
Connect your git repo or use our CLI. A push to main deploys a new immutable version globally in seconds. Rollbacks are one command.
$ nodesail deploy --prod ✓ Building function... (2.1s) ✓ Deploying to 40 regions... (0.8s) ✓ Live: fn.nodesail.app/api/hello
03
It runs. You pay nothing idle.
Your function wakes up when a request arrives, runs, and sleeps again. You're billed in milliseconds of actual execution — not for server hours that sit empty.
Invocations this month: 1,847,293 Execution time: 2.4M ms total Billed: $2.40 Idle cost: $0.00
Supported runtimes
What teams use it for
REST and GraphQL backends for JAMstack frontends — no separate server needed.
Handle Stripe payments, GitHub events, Slack slash commands without a long-running server.
Replace cron servers with time-triggered functions. Run every minute or once a month.
Transform, resize, and optimise images on-demand at the edge.
JWT verification, session checks, and rate limiting before traffic hits your origin.
1 million invocations/month, free forever
No credit card needed to start. Free tier is permanent, not a trial.
Deploy your first function