Build scalable,
dynamic applications
Deploy server-side code that works as API endpoints, runs automatically in response to events, or processes more complex jobs in the background.
How it works
Example use cases
Fetch live data from an API
const API_ENDPOINT = 'https://cat-fact.herokuapp.com/facts'; export default async (request, context) => { try { const response = await fetch(API_ENDPOINT); const data = await response.json(); return Response.json({ data }); } catch (error) { console.log(error); return Response.json({ error: 'Failed fetching data' }, { status: 500 }); } };
Return dynamic images
const API_ROOT = 'https://api.unsplash.com'; export default async (request, context) => { try { const accessKey = process.env.ACCESS_KEY; const doggoEndpoint = `${API_ROOT}/photos/random?client_id=${accessKey}&count=10&collections='3816141,1154337,1254279'`; const response = await fetch(doggoEndpoint); const images = await response.json(); return Response.json({ images }); } catch (error) { console.log(error); return Response.json({ error: 'Failed fetching images' }, { status: 500 }); } };
Send automated email
import formData from "form-data"; import Mailgun from "mailgun.js"; import Airtable from "airtable"; const sendThankYouEmail = async ({ email }) => { console.log('Sending the email'); const { MG_API_KEY: apiKey, MG_DOMAIN: domain } = process.env; const mailgun = new Mailgun(formData).client({ username: 'api', key: apiKey, }); const mailData = { from: `Stefan Judis stefan@${domain}`, to: email, subject: 'Thank you for your interest', text: "I'll come back to you asap!", }; await mailgun.messages.create(domain, mailData); }; const saveUser = async ({ name, email, message }) => { const { AT_API_KEY: apiKey, AT_BASE, AT_TABLE } = process.env; Airtable.configure({ apiKey, }); const base = Airtable.base(AT_BASE); const table = base(AT_TABLE); await table.create({ name, email, message }); }; export default async (request, context) => { try { const data = await request.json(); await sendThankYouEmail(data); if (data.receiveUpdates) { await saveUser(data); } return Response.json({ message: "Let's become serverless conductors!!!" }); } catch (error) { console.log(error); return Response.json({ error: 'Failed sending email' }, { status: 500 }); } };
Validate user input
// Simple Contact Form Spam Filter export default = async (request, context) => { // 1. Parse the form let body try { body = await request.json() } catch (e) { console.log(event) return new Response(`[ERROR] Invalid JSON - ${e.message}`, { status: 400 }) } // 2. Filter if ( !body.data.name || !body.data.message ) { const errorMessage = '[SPAM DETECTED] Required fields not defined.' console.log(errorMessage) return new Response(errorMessage, { status: 200 }) } // 3. Forward data to webhook (ie, send email) try { const res = await fetch(process.env.ZAPIER_CONTACT_FORM_WEBHOOK, { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' } }) return new Response("Success") } catch (error) { console.error("[ERROR] Problem with request:", error) return new Response("[ERROR] Problem with request", { status: 400 }) } }
All part of one amazing workflow
Manage everything in one project
Netlify Functions are files you write in JavaScript, TypeScript, or Go and then place inside your project under the path netlify/functions. (Easy, right? You can even configure that.)
Normally, functions are synchronous with a maximum execution time
of 10 seconds. But, adding
-background
to the end of the filename
transforms any function into an asynchronous function that can run
in the background with up to 15 minutes of runtime.
Build & test locally
You can use Netlify CLI to run a local development server that you can share with others, run a local build and plugins, and deploy your site.
The 2.0 version of our Node-based CLI was rebuilt from the ground up to help improve the site building experience.
Deploy backend functions & frontend code together
Atomically deploy your sites and apps, pushing frontend code and backend functions together, as a unit, without even requiring a maintenance window.
Stage, preview, and rollback
Netlify Functions share all of Netlify’s beloved workflow features. Preview every commit with Deploy Preview links. Rollback when needed by simply clicking a prior deployment.
Run A/B testing and phased rollouts
Deploy and test multiple branches, and even control which users see which version. Plan full experiments and rolling upgrades that include both front and backend code changes. A/B test not just a button color, but an entire user workflow.
New
Export traffic and functions logs
Send traffic and functions data to your favorite log management service for cold storage, troubleshooting, monitoring, and alerting with Log Drains. Available today on Enterprise plans.
Learn moreThe different flavors of compute on Netlify
Netlify provides developers several powerful tools to make websites and web applications both extremely performant and highly dynamic.
Memory | Execution limit | Where it runs | Language | |
---|---|---|---|---|
Serverless functions for Real-time compute | Memory
1024MB
|
Execution limit
10 seconds
|
Where it runs
AWS Lambda
|
Language
JavaScript, TypeScript, or Go
|
Background Functions for long-running tasks | Memory
1024MB
|
Execution limit
15 minutes
|
Where it runs
AWS Lambda
|
Language
JavaScript, TypeScript, or Go
|
Edge Functions for fast personalization | Memory
512MB
|
Execution limit
50ms
|
Where it runs
Deno runtime at network edge
|
Language
JavaScript or TypeScript
|
Build-time compute for prerendering pages in advance | Memory
6 - 36GB
Up to 10 vCPUs |
Execution limit
15 minutes
|
Where it runs
In our build environment
|
Language
Almost any language
|
New! On-demand rendering of pages & assets for large sites | Memory
1024MB
|
Execution limit
10 seconds
|
Where it runs
AWS Lambda
|
Language
JavaScript or TypeScript
|
Moving all LiveChat websites to Netlify has empowered our Web Dev Team to iterate fast and independently.
Pricing for Netlify Functions
Netlify Functions are free to try and available as soon as you activate your account. Pricing scales as your usage grows—from small projects to fully customized enterprise plans.
Level 0 $0 | Level 1 $25 per site /month | Level 2 included with Enterprise plan | |
---|---|---|---|
Requests /month | 125,000 | 2 million | Unlimited(Fair use. For how this is defined for Functions contact Sales) |
Run time /month | 100 hours | 1,000 hours | Unlimited(Fair use. For how this is defined for Functions contact Sales) |
Persistent pages or assets Generated by On-demand Builders | 10,000 | 10,000 | 10,000(Higher limits available for Enterprise) |
Background Functions Available on Pro plans and above | Yes | Yes | Yes |
Deploy to custom AWS account | No | No | Yes |
Extras | No | Add packs of 500,000 requests and 500 runtime hours $19/each | |
Edge Functions Invocations /month | 1 million(then $2 per 1m) | 2 million(Pro plan only, then $2 per 1m) | 5 million (then $2 per 1m, for higher usage - contact Sales) |
Level 0 $0 |
---|
Requests /month |
Run time /month |
Persistent pages or assets |
Background Functions |
Deploy to custom AWS account |
Extras |
Edge Functions |
Level 1 $25 per site /month |
Requests /month |
Run time /month |
Persistent pages or assets |
Background Functions |
Deploy to custom AWS account |
Extras |
Edge Functions |
Level 2 included with Enterprise plan |
Requests /month |
Run time /month |
Persistent pages or assets |
Background Functions |
Deploy to custom AWS account |
Extras |
Edge Functions |
Keep exploring the Netlify Platform
- Netlify Workflow
Netlify Workflow
Work as a team, right in Git. Netlify neatly deploys every resource to the right place, from global static assets to serverless functions.
- Netlify Build
Netlify Build
The Git workflow for web development. Build, deploy, and manage modern web projects.
- Netlify Edge
Netlify Edge
A fast, resilient network for web apps. Connected to your development workflow and designed to handle the most complex tasks - or even to run your own custom logic.
- Addons & Integrations
Addons & Integrations
Add powerful capabilities to every build and integrate easily with other SaaS services. Find the plugins you need from the community or even create your own.