Dense reference for everything from the last five chapters โ deploys, functions, forms, blobs, database, identity, AI gateway, extensions, build plugins, and governance. Copy, paste, ship.
Quick How-To Guides & Fast FixesNeed a quick fix or step-by-step solution? Browse our fast answers on HowTo.KandZ.me:
npm i -g netlify-cli # install globally
netlify login # authenticate
netlify link # associate cwd with a site
netlify init # create + link a new site
netlify dev # local server with functions + redirects
netlify build # run the build locally, same plugins
netlify deploy # draft deploy to a preview URL
netlify deploy --prod # production deploy
netlify open # open the site dashboard
netlify env:list # list env vars (secrets redacted)
netlify env:set KEY value # set a variable
netlify logs:function <name> # tail a function's log
netlify logs:deploy --deploy <id> # fetch a deploy's build log
netlify db init # provision managed Postgres
netlify db connect # SQL session against a branch
netlify extensions:dev # run an extension locally
netlify.toml
[build]
command = "npm run build"
publish = "dist"
functions = "netlify/functions"
# skip the build when nothing that affects output changed
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ."
[build.environment]
NODE_VERSION = "22" # pin the toolchain
[dev]
framework = "#custom"
command = "npm run dev"
port = 8888
[context.production.environment]
API_URL = "https://api.example.com"
[context.deploy-preview.environment]
API_URL = "https://sandbox.example.com"
[[redirects]]
from = "/old/*"
to = "/new/:splat"
status = 301
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
[[redirects]]
from = "/admin/*"
to = "/admin/index.html"
status = 200
force = true
conditions = { Role = ["admin"] }
[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/*"
[headers.values]
Strict-Transport-Security = "max-age=31536000; includeSubDomains"
Referrer-Policy = "strict-origin-when-cross-origin"
[[plugins]]
package = "@netlify/plugin-lighthouse"
Edge Functions
// netlify/edge-functions/auth.ts โ runs at the CDN PoP, no cold start
import type { Config, Context } from "@netlify/edge-functions";
export default async (req: Request, context: Context) => {
const token = context.cookies.get("session");
if (!token) return Response.redirect(new URL("/login", req.url), 302);
// Rewrite to the origin without a redirect round trip
return context.next();
};
export const config: Config = {
path: ["/app/*"], // exact, glob, or an array of both
excludedPath: "/app/public/*",
cache: "manual", // "off" | "manual"
};
# netlify.toml โ control the bundle for one function
[functions]
node_bundler = "esbuild"
external_node_modules = ["sharp"]
[functions.hello]
included_files = ["data/*.json"]
Async Workloads (Workflows)
import { workflow } from "@netlify/workflows";
export const order = workflow("order-process", async ({ step }) => {
// Each step is checkpointed; retries resume from the last success
const o = await step.run("validate", async () => ({ id: "1", ok: true }));
await step.run(
"charge",
{
retries: 5,
backoff: { initialInterval: "10s", multiplier: 2, maxInterval: "1h" },
},
async () => chargeCard(o.id)
);
// Pause for a duration โ no compute, no billing
await step.sleep("trial-end", "3d");
// Pause for an external signal โ resumes on webhook
const shipped = await step.waitForEvent("shipment-delivered", { timeout: "7d" });
});
npx netlify db init # provision Neon Postgres, inject URL
// HTTP driver โ one query per request, no socket, no pool exhaustion
import { neon } from "@netlify/neon";
const sql = neon();
const rows = await sql`SELECT * FROM notes WHERE published = ${true} LIMIT ${20}`;
// TCP driver โ required for sessions and transactions
import { Pool } from "@neondatabase/serverless";
let pool;
const getPool = () => (pool ??= new Pool({
connectionString: process.env.NETLIFY_DATABASE_URL,
max: 3,
}));
const c = await getPool().connect();
try {
await c.query("BEGIN");
/* ... */
await c.query("COMMIT");
} catch (e) {
await c.query("ROLLBACK");
throw e;
} finally {
c.release();
}
-- netlify/database/migrations/20250114103000_add_notes.sql
CREATE TABLE IF NOT EXISTS notes (
id bigserial PRIMARY KEY,
title text NOT NULL,
published boolean NOT NULL DEFAULT false
);
-- Safe column addition: nullable โ backfill โ constrain
ALTER TABLE notes ADD COLUMN IF NOT EXISTS slug text;
UPDATE notes SET slug = lower(title) WHERE slug IS NULL;
ALTER TABLE notes ALTER COLUMN slug SET NOT NULL;
// src/ui/main.tsx โ use the SDK fetch client, not window.fetch
import { NetlifyExtensionUIFetchClient } from "@netlify/sdk/ui/react";
const client = new NetlifyExtensionUIFetchClient();
client.fetch("/api/summary").then((r) => r.json());
// One JSON object per line โ filterable, not greppable
const log = (level, msg, extra = {}) =>
console.log(JSON.stringify({
level,
msg,
route: "checkout",
country: context.geo?.country?.code,
ms: Date.now() - t0,
...extra,
}));
// Cache a function response at the edge โ repeats cost no invocation
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, max-age=60, stale-while-revalidate=300",
},
});