Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
netlify avatar

Netlify Functions

  • 1.5k installs
  • 31 repo stars
  • Updated August 4, 2026
  • netlify/context-and-tools

netlify-functions is a Claude skill that guides developers in writing modern Netlify serverless functions with TypeScript, routing, scheduled jobs, and streaming responses for server-side API logic.

About

netlify-functions is a Claude skill for authoring Netlify serverless functions using the modern default export plus Config pattern with `@netlify/functions` types—never legacy `exports.handler`. It covers API endpoints, background processing, scheduled functions, HTTP method routing, path routing, and streaming `Response` objects in TypeScript. Developers reach for netlify-functions when adding server-side logic to Netlify-hosted sites: webhooks, cron tasks, authenticated APIs, or streamed LLM output. The skill enforces current syntax, correct `Context` and `Config` usage, and platform-specific patterns so handlers deploy cleanly on Netlify without deprecated export styles or missing route configuration.

  • Enforces modern default-export + Config pattern instead of legacy handler syntax
  • Generates correct file structure with support for shared code, index routing, and custom paths
  • Covers background functions, scheduled functions, streaming responses, and method-based routing
  • Produces ready-to-deploy TypeScript or JavaScript functions compatible with Netlify platform
  • Includes full Context and Config type handling for production-grade serverless endpoints

Netlify Functions by the numbers

  • 1,495 all-time installs (skills.sh)
  • +120 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #325 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/netlify/context-and-tools --skill netlify-functions

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.5k
repo stars31
Last updatedAugust 4, 2026
Repositorynetlify/context-and-tools

How do you write modern Netlify serverless functions in TypeScript?

Quickly produce correct, modern Netlify serverless functions with proper routing, TypeScript support, scheduled tasks, and streaming responses.

Who is it for?

Full-stack developers on Netlify who need API routes, cron jobs, or streaming endpoints without migrating to a separate backend host.

Skip if: Teams deploying exclusively on AWS Lambda, Cloudflare Workers, or long-running Node servers outside Netlify Functions.

When should I use this skill?

The user creates Netlify API endpoints, background jobs, scheduled tasks, or server-side logic with Netlify Functions.

What you get

TypeScript Netlify function handlers, Config exports, route definitions, and scheduled or background function setup.

  • TypeScript function handlers
  • Config route definitions
  • scheduled function setup

Files

SKILL.mdMarkdownGitHub ↗

Netlify Functions

Modern Syntax

Always use the modern default export + Config pattern. Never use the legacy exports.handler or named handler export.

import type { Context, Config } from "@netlify/functions";

export default async (req: Request, context: Context) => {
  return new Response("Hello, world!");
};

export const config: Config = {
  path: "/api/hello",
};

The handler receives a standard Web API Request and returns a Response. The second argument is a Netlify Context object.

The bare default export shown above is the recommended form. The default export can also be an object with a fetch method — prefer this form only if (1) other functions in the project already use it, or (2) the function also subscribes to platform events (see Event Handlers below), since events are exposed as named handlers on the same object:

export default {
  fetch(req: Request, context: Context) {
    return new Response("Hello, world!");
  },
};

File Structure

Place functions in netlify/functions/:

netlify/functions/
  _shared/           # Non-function shared code (underscore prefix)
    auth.ts
    db.ts
  items.ts           # -> /.netlify/functions/items (or custom path via config)
  users/index.ts     # -> /.netlify/functions/users

Use .ts or .mts extensions. If both .ts and .js exist with the same name, the .js file takes precedence.

Path Routing

Define custom paths via the config export:

export const config: Config = {
  path: "/api/items",                    // Static path
  // path: "/api/items/:id",            // Path parameter
  // path: ["/api/items", "/api/items/:id"], // Multiple paths
  // excludedPath: "/api/items/special", // Excluded paths
  // preferStatic: true,                // Don't override static files
};

Without a path config, functions are available at /.netlify/functions/{name}. Setting a path makes the function available only at that path.

Access path parameters via context.params:

// config: { path: "/api/items/:id" }
export default async (req: Request, context: Context) => {
  const { id } = context.params;
  // ...
};

Method Routing

export default async (req: Request, context: Context) => {
  switch (req.method) {
    case "GET":    return handleGet(context.params.id);
    case "POST":   return handlePost(await req.json());
    case "DELETE": return handleDelete(context.params.id);
    default:       return new Response("Method not allowed", { status: 405 });
  }
};

export const config: Config = {
  path: "/api/items/:id",
  method: ["GET", "POST", "DELETE"],
};

Background Functions

For long-running tasks (up to 15 minutes). The client receives an immediate 202 response; return values are ignored.

Enable background mode by setting background: true in config:

export default async (req: Request) => {
  await someLongRunningTask();
};

export const config: Config = {
  path: "/process",
  background: true,
};

Store results externally (Netlify Blobs, database) for later retrieval.

The legacy filename convention (process-background.ts) is still supported, but new functions should use config.background.

Resource Configuration

Functions default to 1024 MB of memory and a proportional amount of compute. Configure per-function resources via memory or vcpu — they scale together, so set whichever maps to how you think about the workload. The two are mutually exclusive.

export const config: Config = {
  memory: "2gb",  // or memory: 2048; allowed range 1024–4096 MB
  // vcpu: 1.5,   // alternatively; allowed range 0.5–2.0
};
  • memory: number (MB) or string with unit ("2gb", "1024mb", case-insensitive).
  • vcpu: number between 0.5 and 2.0. Maps linearly: 0.5 → 1024 MB, 2.0 → 4096 MB.

Both can also be set in netlify.toml:

[functions.heavy]
  memory = "2gb"

Region

Override the deployment region per function via the region property. Accepts an airport code (iad, dub, fra, lhr, nrt, pdx, sfo, sin, syd, yul, cmh, gru).

export const config: Config = {
  region: "dub",  // Dublin (eu-west-1)
};

Falls back to the site-level region if unset. Plan-gated; some plans don't allow region overrides.

Scheduled Functions

Run on a cron schedule (UTC timezone):

export default async (req: Request) => {
  const { next_run } = await req.json();
  console.log("Next invocation at:", next_run);
};

export const config: Config = {
  schedule: "@hourly", // or cron: "0 * * * *"
};

Shortcuts: @yearly, @monthly, @weekly, @daily, @hourly. Scheduled functions have a 30-second timeout and only run on published deploys.

Streaming Responses

Return a ReadableStream body for streamed responses (up to 20 MB):

export default async (req: Request) => {
  const stream = new ReadableStream({ /* ... */ });
  return new Response(stream, {
    headers: { "Content-Type": "text/event-stream" },
  });
};

Event Handlers

A function can subscribe to platform events by exporting an object instead of a function as its default. Each event has a named handler property:

import type { DeploySucceededEvent, UserSignupEvent } from "@netlify/functions";

export default {
  deploySucceeded(event: DeploySucceededEvent) {
    console.log(`Deploy ${event.deploy.id} succeeded`);
  },

  userSignup(event: UserSignupEvent) {
    return {
      user: {
        ...event.user,
        appMetadata: { ...event.user.appMetadata, roles: ["member"] },
      },
    };
  },
};

A single function can declare multiple handlers; multiple functions can also subscribe to the same event.

Available handlers:

HandlerTrigger
fetchHTTP request (equivalent to a bare function default export)
deployBuilding / deploySucceeded / deployFailed / deployDeleted / deployLocked / deployUnlockedDeploy lifecycle
userSignup / userLogin / userValidate / userModified / userDeletedIdentity lifecycle
formSubmittedForm submission verified

Identity handlers: deny an action

userSignup, userLogin, userValidate, and userModified can reject the action by calling event.deny(). The end user receives a 401; no observability error is produced (unlike throwing).

export default {
  userLogin(event: UserLoginEvent) {
    if (!event.user.email?.endsWith("@example.com")) {
      return event.deny();
    }
  },
};

If multiple functions subscribe to the same event, the first to call event.deny() aborts the chain.

Context Object

PropertyDescription
context.paramsPath parameters from config
context.geo{ city, country: {code, name}, latitude, longitude, subdivision, timezone, postalCode }
context.ipClient IP address
context.cookies.get(), .set(), .delete()
context.deploy{ context, id, published }
context.site{ id, name, url }
context.account.idTeam account ID
context.requestIdUnique request ID
context.waitUntil(promise)Extend execution after response is sent

Environment Variables

Use Netlify.env (not process.env) inside functions:

const apiKey = Netlify.env.get("API_KEY");

Resource Limits

ResourceLimit
Synchronous timeout60 seconds
Background timeout15 minutes
Scheduled timeout30 seconds
Memory1024 MB default; configurable 1024–4096 MB (see Resource Configuration)
Buffered payload6 MB
Streamed payload20 MB

Framework Considerations

Frameworks with server-side capabilities (Astro, Next.js, Nuxt, SvelteKit, TanStack Start) typically generate their own serverless functions via adapters. You usually do not write raw Netlify Functions in these projects — the framework adapter handles server-side rendering and API routes. Write Netlify Functions directly when:

  • Using a client-side-only framework (Vite + React SPA, vanilla JS)
  • Adding background or scheduled tasks to any project
  • Building standalone API endpoints outside the framework's routing

See the netlify-frameworks skill for adapter setup.

Related skills

How it compares

Choose netlify-functions for Netlify-hosted serverless APIs; use Vercel or AWS Lambda skills when the deployment target is not Netlify.

FAQ

Which export pattern does netlify-functions require?

netlify-functions mandates the modern default export plus Config pattern using `import type { Context, Config } from '@netlify/functions'`. Legacy `exports.handler` and named `handler` exports are explicitly disallowed.

What Netlify function types does the skill cover?

netlify-functions covers standard API endpoints, background functions, scheduled functions, path and method routing, and streaming HTTP responses. All examples use TypeScript with the current Netlify Functions syntax.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.