import formData from"form-data";import Mailgun from"mailgun.js";import Airtable from"airtable";constsendThankYouEmail=async({ email })=>{
console.log('Sending the email');const{MG_API_KEY: apiKey,MG_DOMAIN: domain }= process.env;const mailgun =newMailgun(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);};constsaveUser=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 });};exportdefaultasync(request, context)=>{try{const data =await request.json();awaitsendThankYouEmail(data);if(data.receiveUpdates){awaitsaveUser(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
Validate.js
// Simple Contact Form Spam Filterexportdefault=async(request, context)=>{// 1. Parse the formlet body
try{
body =await request.json()}catch(e){
console.log(event)returnnewResponse(`[ERROR] Invalid JSON - ${e.message}`,{status:400})}// 2. Filterif(!body.data.name ||!body.data.message ){const errorMessage ='[SPAM DETECTED] Required fields not defined.'
console.log(errorMessage)returnnewResponse(errorMessage,{status:200})}// 3. Forward data to webhook (ie, send email)try{const res =awaitfetch(process.env.ZAPIER_CONTACT_FORM_WEBHOOK,{method:'POST',body:JSON.stringify(body),headers:{'Content-Type':'application/json'}})returnnewResponse("Success")}catch(error){
console.error("[ERROR] Problem with request:", error)returnnewResponse("[ERROR] Problem with request",{status:400})}}
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.
Netlify provides developers several powerful tools to make websites and
web applications both extremely performant and highly
dynamic.
A comparison table for the different flavors of compute on
Netlify
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.
Functions pricing table
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
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.
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.
We use cookies to improve your browsing experience and for marketing purposes.Read our Privacy Policy
Privacy Preference Center
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
Manage Consent Preferences
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
Social Media Cookies
These cookies are set by a range of social media services that we have added to the site to enable you to share our content with your friends and networks. They are capable of tracking your browser across other sites and building up a profile of your interests. This may impact the content and messages you see on other websites you visit. If you do not allow these cookies you may not be able to use or see these sharing tools.
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
Targeting Cookies
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.