Skip to content
For the complete Netlify documentation index, see llms.txt. Markdown versions of this page are available by appending .md to the URL.

Unlimited seats on Netlify Pro for $20/month → Learn more 👥

Functions overview

For the complete documentation index, see llms.txt

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.

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.

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.

netlify/functions/hello.mts
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",
}

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:

netlify/functions/hello.mts
import type { NetlifyFunction } from "@netlify/functions"
export default {
fetch: (req, context) => {
return new Response("Hello, world!")
},
config: {
path: "/hello",
},
} satisfies NetlifyFunction

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.

netlify/functions/on-deploy.mts
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.

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.