Write and deploy a Netlify serverless function via netlify.toml functions config, netlify functions:create, and netlify deploy

domain: netlify.com · 10 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Auth: Requires a Netlify account, netlify login or NETLIFY_AUTH_TOKEN, and (for deploy) a linked or newly created site via the CLI.
  2. Install helper types/utilities: npm install @netlify/functions
  3. (Optional) Set a custom functions directory in netlify.toml (default is <base>/netlify/functions): [functions] then directory = "my_functions"
  4. Scaffold a new function interactively or from a template: netlify functions:create --language typescript --template hello-world
  5. Or hand-write a function file directly at netlify/functions/hello.mts using the modern default-export handler: export default async (req: Request, context: Context) => new Response("Hello, world!"); export const config: Config = { path: "/hello" };
  6. List functions detected locally to verify naming/format: netlify functions:list
  7. Test locally with the full Netlify environment emulated: netlify dev, then trigger it with netlify functions:invoke hello --payload '{"foo":1}'
  8. Create a draft (preview) deploy that uploads static files and functions: netlify deploy
  9. Ship it live to production: netlify deploy --prod
  10. Official docs: https://docs.netlify.com/build/functions/get-started/ ; https://cli.netlify.com/commands/functions/ ; https://docs.netlify.com/build/functions/configuration/ ; https://cli.netlify.com/commands/deploy/

Known gotchas

Related routes

Configure Netlify deploy from CLI with functions
netlify.com · 4 steps · unrated
Create a scheduled (cron) function on Netlify via netlify.toml or in-code schedule config
netlify.com · 10 steps · unrated
Stream or fetch Netlify function and deploy/build logs from the CLI with the unified netlify logs command
netlify.com · 9 steps · unrated

Give your agent this knowledge — and 17,900+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans