For the complete Netlify documentation index, see llms.txt. Markdown versions of this page are available by appending .md to the URL. With Netlify Functions, you can build full-stack applications without having to manage servers. Whether you’re experimenting with your first application or handling millions of requests, Netlify gives you the infrastructure that automatically scales as you grow.
Your functions are version-controlled, built, and deployed along with the rest of your Netlify site, giving you the power of Deploy Previews and instant rollbacks.
Seamless integrations with Database, Blobs, Caching, and AI Gateway give you a powerful foundation to build any full-stack application on Netlify.
How functions work
Section titled “How functions work”A function is a file in your project that contains server-side code for responding to an event.
When the event happens, Netlify hands your code the event payload, runs it in an ephemeral runtime environment, and acts on whatever it returns. The infrastructure automatically scales according to the volume of traffic to your site, so that the performance stays consistent no matter the load.
For web requests, the function returns a response that is delivered to the client. For other types of events, the function’s return value can influence what happens next on the platform — for example, an identity handler can mutate a user record or reject a sign-up.
Web requests
Section titled “Web requests”The most common event is a web request to your site. Your function receives a Request and a Context, and returns a Response that is delivered back to the client.
You can use the config object to configure different aspects of your function, such as the URL paths that the function runs on or the HTTP method it responds to.
import type { Config, Context } from "@netlify/functions"
export default async (req: Request, context: Context) => { return new Response("Hello, world!")}
export const config: Config = { path: "/hello",}import type { Config } from "@netlify/functions"import { getDatabase } from "@netlify/database"
const db = getDatabase()
export default async (req: Request) => { const users = await db.sql`SELECT id, email FROM users LIMIT 10`
return Response.json({ users })}
export const config: Config = { path: "/users",}import type { Config } from "@netlify/functions"import { getStore } from "@netlify/blobs"
export default async (req: Request) => { const uploads = getStore("uploads") const key = crypto.randomUUID()
await uploads.set(key, await req.blob())
return Response.json({ key })}
export const config: Config = { method: "POST", path: "/upload",}import type { Config, Context } from "@netlify/functions"import OpenAI from "openai"
const client = new OpenAI()
export default async (req: Request, context: Context) => { const response = await client.responses.create({ model: "gpt-5-mini", input: [{ role: "user", content: `Write a haiku about ${context.params.topic}.` }], })
return Response.json({ haiku: response.output_text })}
export const config: Config = { path: "/haiku/:topic",}Alternatively, you can use the web platform fetch syntax for interoperability with JavaScript frameworks and runtimes that share this convention. Export an object with a fetch method instead of a bare default function:
import type { NetlifyFunction } from "@netlify/functions"
export default { fetch: (req, context) => { return new Response("Hello, world!") },
config: { path: "/hello", },} satisfies NetlifyFunctionimport type { NetlifyFunction } from "@netlify/functions"import { getDatabase } from "@netlify/database"
const db = getDatabase()
export default { fetch: async (req) => { const users = await db.sql`SELECT id, email FROM users LIMIT 10`
return Response.json({ users }) },
config: { path: "/users", },} satisfies NetlifyFunctionimport type { NetlifyFunction } from "@netlify/functions"import { getStore } from "@netlify/blobs"
export default { fetch: async (req) => { const uploads = getStore("uploads") const key = crypto.randomUUID()
await uploads.set(key, await req.blob())
return Response.json({ key }) },
config: { method: "POST", path: "/upload", },} satisfies NetlifyFunctionimport type { NetlifyFunction } from "@netlify/functions"import OpenAI from "openai"
const client = new OpenAI()
export default { fetch: async (req, context) => { const response = await client.responses.create({ model: "gpt-5-mini", input: [{ role: "user", content: `Write a haiku about ${context.params.topic}.` }], })
return Response.json({ haiku: response.output_text }) },
config: { path: "/haiku/:topic", },} satisfies NetlifyFunctionPlatform events
Section titled “Platform events”A function can also subscribe to platform events on your Netlify project, like a deploy completing, a form submission, or a user signup. To subscribe to one or more events, export an object whose properties are named event handlers, including a fetch handler for web requests if you want it.
import type { Context, DeploySucceededEvent } from "@netlify/functions"
export default { // Responds to web requests, same as a bare default export. fetch(req: Request, context: Context) { return new Response("Hello, world!") },
// Runs after every successful deploy. deploySucceeded(event: DeploySucceededEvent) { console.log(`Deploy ${event.deploy.id} has shipped! 🚀`) },}Refer to Get started with functions for the full walkthrough or Trigger functions on events for the list of supported events.
Manage your functions
Section titled “Manage your functions”Functions deployed from Netlify are immutable. This means that an update to a function on your production branch won’t change the version that was deployed in a branch deploy, or in a Deploy Preview. You can access all versions of your functions in the Netlify web interface, under the Functions tab.
By default, the list displays all of the functions, including background functions, in the current published deploy. To find functions on another deploy, you can use the search field at the top of the list. You can start typing to jump to a particular branch, or find a Deploy Preview by number.
More Functions resources
Section titled “More Functions resources”- Get started with functions
- API reference
- Configuration for functions
- Trigger functions on events
- Use Identity in functions
- Background Functions overview
- Scheduled Functions overview
- Environment variables and functions
- Function logs
- Functions usage and billing
- Function Metrics
- Visit our Forums to join the conversation about Functions
Did you find this doc useful?
Your feedback helps us improve our docs.