Skip to main content

# Advanced: Vercel Edge Functions, Analytics & Team Workflows

Edge Functions: Code at the CDN Edge

Standard serverless functions run in a single region (usually us-east-1). Edge Functions run globally — on the CDN node closest to each user. This means sub-50ms response times worldwide.

// app/api/geo/route.ts
export const runtime = 'edge'; // This is the key line

export async function GET(request: Request) {
  // Vercel injects geo data at the edge
  const country = request.headers.get('x-vercel-ip-country') || 'US';
  const city = request.headers.get('x-vercel-ip-city') || 'Unknown';

  return Response.json({
    greeting: `Hello from ${city}, ${country}!`,
    timestamp: Date.now(),
  });
}

When to use Edge vs. Node.js runtime: - Edge: Authentication checks, geo-routing, personalization, A/B testing, simple API responses - Node.js: Database queries (most DB clients need Node.js), file system access, heavy computation, packages that use Node.js APIs

Edge limitations: No fs module, no native Node.js modules, 128KB code size limit after compression, limited NPM package compatibility. The edge runtime uses V8 isolates (like Cloudflare Workers), not full Node.js.

Unlock this lesson

Upgrade to Pro to access the full content

What you'll learn:

  • Write and deploy Edge Functions for low-latency global execution
  • Use Vercel Analytics and Speed Insights to monitor real-user performance
  • Set up team workflows with deployment protection and role-based access