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 👥

Get started with functions

For the complete documentation index, see llms.txt

This page walks you through creating your first Netlify function. For the conceptual overview of how functions work, see Functions overview.

Select your function language:

Add the @netlify/functions module to your project. It exports the types you need to write type-safe functions.

Terminal window
npm install @netlify/functions

You don’t need any additional tooling. If you want to extend TypeScript’s base configuration, you can provide your own tsconfig.json. Our build system loads tsconfig.json files from your functions directory, the repository root, or the base directory.

Create a TypeScript file in your functions directory, which defaults to netlify/functions/. You can put the file directly in that folder or in a subdirectory; if you use a subdirectory, the entry file must be named index or match the subdirectory name.

For example, any of these would create a function called hello:

  • netlify/functions/hello.mts
  • netlify/functions/hello/hello.mts
  • netlify/functions/hello/index.mts

A function file has a default export with a handler that receives a web platform Request and a Netlify-specific Context, and returns a web platform Response.

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",
}

Once deployed, the function is available at https://<YOUR DOMAIN>/hello. For additional routing configuration options, see Configuration → Routing.

If you’d rather describe what your function should do than write the code yourself, an AI coding agent can scaffold the function for you. You can use a local agent like Claude Code or Codex against your project, or use Netlify’s Agent Runners, which run AI coding agents directly on your Netlify project and commit the changes for you.

A prompt as simple as the following will produce a working function:

Add a Netlify function at `/api/joke` that returns a random programming joke as JSON.

For more, see the Agent Runners overview and example prompts.

Most modern frameworks include native support for Netlify Functions in their dev server, so you can run and test your function locally without any extra tooling.

If you’re using a Vite-based framework, like Astro, Nuxt, TanStack Start, or React Router, just run your framework’s dev server. The @netlify/vite-plugin emulates the Netlify platform inside the dev server, so functions, edge functions, blobs, environment variables, and other primitives behave the same locally as in production.

Alternatively, the Netlify CLI starts a framework server (if one is detected) and handles redirects, proxy rules, environment variables, and Netlify Functions through a simulated Netlify production environment.

Push your function source files to your Git provider for continuous deployment where Netlify’s build system automatically detects, builds, and deploys your functions. You can also deploy manually with the Netlify CLI or API.

Monitor function logs and metrics in the Netlify UI to observe and help troubleshoot your deployed functions.

Netlify function logs are found in the Netlify UI. You can also stream Netlify function logs to the console with the Netlify CLI.

Optionally add the @netlify/functions module to your project. It’s not required for JavaScript functions, but it provides helper exports if you ever opt in.

Terminal window
npm install @netlify/functions

Create a JavaScript file in your functions directory — by default that’s netlify/functions/. You can put the file directly in that folder or in a subdirectory; if you use a subdirectory, the entry file must be named index or match the subdirectory name.

For example, any of these would create a function called hello:

  • netlify/functions/hello.mjs
  • netlify/functions/hello/hello.mjs
  • netlify/functions/hello/index.mjs

A function file has a default export with a handler that receives a web platform Request and a Netlify-specific context, and returns a web platform Response.

netlify/functions/hello.mjs
export default async (req, context) => {
return new Response("Hello, world!")
}
export const config = {
path: "/hello",
}

Once deployed, the function is available at https://<YOUR DOMAIN>/hello. For additional routing configuration options, see Configuration → Routing.

If you’d rather describe what your function should do than write the code yourself, an AI coding agent can scaffold the function for you. You can use a local agent like Claude Code or Codex against your project, or use Netlify’s Agent Runners, which run AI coding agents directly on your Netlify project and commit the changes for you.

A prompt as simple as the following will produce a working function:

Add a Netlify function at `/api/joke` that returns a random programming joke as JSON.

For more, see the Agent Runners overview and example prompts.

Most modern frameworks include native support for Netlify Functions in their dev server, so you can run and test your function locally without any extra tooling.

If you’re using a Vite-based framework, like Astro, Nuxt, TanStack Start, or React Router, just run your framework’s dev server. The @netlify/vite-plugin emulates the Netlify platform inside the dev server, so functions, edge functions, blobs, environment variables, and other primitives behave the same locally as in production.

Alternatively, the Netlify CLI starts a framework server (if one is detected) and handles redirects, proxy rules, environment variables, and Netlify Functions through a simulated Netlify production environment.

Push your function source files to your Git provider for continuous deployment where Netlify’s build system automatically detects, builds, and deploys your functions. You can also deploy manually with the Netlify CLI or API.

Monitor function logs and metrics in the Netlify UI to observe and help troubleshoot your deployed functions.

Netlify function logs are found in the Netlify UI. You can also stream Netlify function logs to the console with the Netlify CLI.

To write functions in Go, use the Lambda-compatible functions API.