Skip to content

Netlify Reference

Netlify excels at JAMstack deployment and modern web workflows:

  • 🏗️ Static Site Generators - Jekyll, Hugo, Gatsby, etc.
  • 🔧 Build Automation - CI/CD from Git
  • 📝 Form Handling - No backend required
  • 🌐 Edge Functions - Serverless at the edge
domains/username.json
{
"owner": {
"username": "username",
"email": "user@example.com"
},
"records": {
"CNAME": "app-name.netlify.app"
}
}
  • Git Integration: Connect GitHub/GitLab/Bitbucket
  • Manual Deploy: Drag & drop build folder
  • CLI Deploy: Use Netlify CLI tool
  1. Site DashboardDomain settings
  2. Add custom domainusername.loves-to.dev
  3. Netlify shows DNS configuration
  4. Use your Netlify URL as CNAME target
  • Automatically provisions Let’s Encrypt certificate
  • Usually ready within 1-10 minutes
  • Force HTTPS redirect available
netlify.toml
[build]
publish = "dist"
command = "npm run build"
[build.environment]
NODE_VERSION = "18"
NPM_VERSION = "9"
# Redirect rules
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
# Custom headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
Referrer-Policy = "same-origin"
# Form handling
[[headers]]
for = "/contact"
[headers.values]
X-Robots-Tag = "noindex"
FrameworkBuild CommandPublish Directory
Reactnpm run buildbuild
Vuenpm run builddist
Gatsbygatsby buildpublic
Hugohugopublic
Jekyllbundle exec jekyll build_site
Astronpm run builddist
netlify/
└── functions/
├── hello.js
├── api.js
└── contact-form.js
netlify/functions/hello.js
exports.handler = async (event, context) => {
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "Hello from loves-to.dev!",
method: event.httpMethod,
path: event.path
}),
}
}
netlify/functions/api.js
exports.handler = async (event, context) => {
const { httpMethod, body, queryStringParameters } = event;
if (httpMethod === 'GET') {
return {
statusCode: 200,
body: JSON.stringify({ data: "API response" }),
}
}
if (httpMethod === 'POST') {
const data = JSON.parse(body);
return {
statusCode: 201,
body: JSON.stringify({ received: data }),
}
}
return {
statusCode: 405,
body: 'Method Not Allowed',
}
}
contact.html
<form name="contact" method="POST" data-netlify="true">
<p>
<label>Name: <input type="text" name="name" required /></label>
</p>
<p>
<label>Email: <input type="email" name="email" required /></label>
</p>
<p>
<label>Message: <textarea name="message" required></textarea></label>
</p>
<p>
<button type="submit">Send</button>
</p>
</form>
ContactForm.jsx
import React, { useState } from 'react';
const ContactForm = () => {
const [formData, setFormData] = useState({});
const handleSubmit = (e) => {
e.preventDefault();
// Netlify handles the form submission automatically
};
return (
<form
name="contact"
method="POST"
data-netlify="true"
onSubmit={handleSubmit}
>
<input type="hidden" name="form-name" value="contact" />
{/* Form fields */}
</form>
);
};
Site settings → Environment variables
NODE_ENV=production
GATSBY_SITE_URL=https://username.loves-to.dev
HUGO_VERSION=0.110.0
netlify/functions/config.js
exports.handler = async (event, context) => {
const apiKey = process.env.API_KEY;
const siteUrl = process.env.URL; // Netlify provides this automatically
return {
statusCode: 200,
body: JSON.stringify({ siteUrl }),
}
}
  • Every pull request gets a unique preview URL
  • Format: deploy-preview-123--site-name.netlify.app
  • Perfect for testing before merging
netlify.toml
[context.deploy-preview]
command = "npm run build:preview"
[context.deploy-preview.environment]
NODE_ENV = "preview"
netlify.toml
[build.processing]
skip_processing = false
[build.processing.css]
bundle = true
minify = true
[build.processing.js]
bundle = true
minify = true
[build.processing.html]
pretty_urls = true
[build.processing.images]
compress = true
netlify/edge-functions/geolocation.js
export default async (request, context) => {
const country = context.geo.country?.code || 'US';
return new Response(JSON.stringify({
country,
message: `Hello from ${country}!`
}), {
headers: { 'content-type': 'application/json' },
});
};
  • Check Node.js version in build settings
  • Verify all dependencies are installed
  • Review deploy logs for specific errors
  • Ensure data-netlify="true" attribute is present
  • Add name attribute to form element
  • Check spam folder for notifications
  • Free tier: 10 seconds max execution time
  • Pro tier: 26 seconds max execution time
  • Optimize function performance
  • Verify CNAME points to correct Netlify URL
  • Check for conflicting DNS records
  • Wait up to 48 hours for propagation