1. Home
  2. /
  3. Supabase-edge-functions
  4. /
  5. Supabase Edge Function Using Environment Variable

Supabase Edge Function Using Environment Variable - Supabase-edge-functions Typing CST Test

Loading…

Supabase Edge Function Using Environment Variable — Supabase-edge-functions Code

Uses environment variables in the function.

# supabase/demo/env.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';

serve((_req) => {
	const apiKey = Deno.env.get('MY_API_KEY') || 'NotSet';
	return new Response(`API Key length: ${apiKey.length}`, { status: 200 });
});

Supabase-edge-functions Language Guide

Supabase Edge Functions are serverless functions deployed at the edge using Deno runtime, enabling developers to run backend logic close to users with low latency.

Primary Use Cases

  • ▸RESTful API endpoints for Supabase apps
  • ▸Custom authentication or authorization flows
  • ▸Processing webhooks and events
  • ▸Serverless business logic triggered by frontend requests
  • ▸Realtime event handling and notifications

Notable Features

  • ▸Automatic scaling with traffic
  • ▸Runs on Deno runtime for secure execution
  • ▸Supports JavaScript and TypeScript
  • ▸Tight integration with Supabase ecosystem
  • ▸Edge-deployed for low-latency responses

Origin & Creator

Supabase Edge Functions were launched by Supabase in 2021 as part of their serverless edge platform.

Industrial Note

Supabase Edge Functions are optimized for developers looking to extend Supabase applications with serverless backend logic that runs near users worldwide.

Quick Explain

  • ▸Edge Functions execute JavaScript or TypeScript code in response to HTTP requests or custom triggers.
  • ▸Built on the Deno runtime, they provide secure, fast, and modern serverless execution.
  • ▸Functions automatically scale based on incoming requests without server management.
  • ▸Tightly integrated with Supabase services such as database, auth, storage, and Realtime.
  • ▸Ideal for building APIs, webhooks, authentication flows, and custom backend logic at low latency.

Core Features

  • ▸Function-as-a-Service (FaaS) model at the edge
  • ▸HTTP request and response handling
  • ▸Access Supabase services (Postgres, Storage, Auth, Realtime)
  • ▸Environment variables for runtime configuration
  • ▸Secure execution with Deno sandbox

Learning Path

  • ▸Learn TypeScript / JavaScript basics
  • ▸Understand serverless and edge concepts
  • ▸Install Supabase CLI and connect project
  • ▸Write Edge Functions with Supabase client
  • ▸Deploy, monitor, and scale edge functions

Practical Examples

  • ▸User authentication and token verification
  • ▸CRUD APIs for Supabase Postgres
  • ▸Webhook handler for third-party integrations
  • ▸Serverless image processing using Supabase storage
  • ▸Realtime notifications and event broadcasting

Comparisons

  • ▸Supabase Edge Functions vs AWS Lambda: Edge-deployed with Deno vs region-based serverless
  • ▸Supabase vs Cloudflare Workers: Supabase tightly integrated with backend DB/Auth vs Workers edge-first general-purpose
  • ▸Supabase vs Vercel Functions: Supabase for DB-heavy apps, Vercel for frontend-focused APIs
  • ▸Supabase vs Netlify Functions: Supabase edge functions integrate with Postgres, Netlify is generic FaaS
  • ▸Supabase vs Node.js server: No servers required, auto-scaled, edge-located functions

Strengths

  • ▸Ultra-low latency for global users
  • ▸Integrated seamlessly with Supabase backend
  • ▸Serverless - no server provisioning required
  • ▸Supports modern TypeScript/JavaScript
  • ▸Easy to deploy and scale automatically

Limitations

  • ▸Execution time is limited (short-lived requests)
  • ▸Vendor lock-in to Supabase platform
  • ▸Cold starts may affect first requests
  • ▸Limited runtime compared to full server environments
  • ▸Debugging and monitoring require Supabase tooling

When NOT to Use

  • ▸Heavy computational tasks
  • ▸Long-running jobs exceeding function limits
  • ▸Applications needing fine-grained infrastructure control
  • ▸Workflows requiring complex orchestration beyond HTTP triggers
  • ▸Non-Supabase projects without database/auth integration

Cheat Sheet

  • ▸supabase functions init -> create new function project
  • ▸supabase functions serve -> run locally
  • ▸supabase functions deploy -> deploy to edge
  • ▸supabase functions list -> list deployed functions
  • ▸supabase secrets set -> store environment variables securely

FAQ

  • ▸Are Supabase Edge Functions free?
  • ▸Yes - free tier available, paid tiers expand limits.
  • ▸Which languages are supported?
  • ▸JavaScript and TypeScript using Deno runtime.
  • ▸Do functions scale automatically?
  • ▸Yes - automatically scale with incoming requests.
  • ▸Can functions maintain state?
  • ▸No - functions are stateless; use Postgres or Storage for persistence.
  • ▸Can I deploy functions globally?
  • ▸Yes - functions run at edge locations managed by Supabase.

30-Day Skill Plan

  • ▸Week 1: JS/TS and Supabase CLI setup
  • ▸Week 2: Create simple HTTP functions
  • ▸Week 3: Integrate Postgres and Storage
  • ▸Week 4: Implement auth and webhook handlers
  • ▸Week 5: Optimize functions and monitor edge performance

Final Summary

  • ▸Supabase Edge Functions are serverless, edge-deployed functions using Deno runtime.
  • ▸Designed for low-latency backend logic, tightly integrated with Supabase services.
  • ▸Supports TypeScript/JavaScript, environment variables, and HTTP triggers.
  • ▸Automatic scaling and serverless execution with minimal infrastructure.
  • ▸Ideal for API endpoints, authentication flows, webhooks, and lightweight business logic.

Project Structure

  • ▸functions/ - folder containing each Edge Function
  • ▸supabase/ - Supabase project config
  • ▸package.json - dependencies
  • ▸tsconfig.json - TypeScript config
  • ▸tests/ - unit and integration tests

Monetization

  • ▸Serverless backend for Supabase-based SaaS
  • ▸Edge API endpoints for web and mobile apps
  • ▸Custom business logic processing
  • ▸Webhook integrations for clients
  • ▸Event-driven notifications and automation

Productivity Tips

  • ▸Keep functions lightweight and stateless
  • ▸Use Supabase Postgres/Storage for persistence
  • ▸Leverage Supabase CLI for deployment and testing
  • ▸Monitor edge performance regularly
  • ▸Combine multiple functions for modular architecture

Basic Concepts

  • ▸Function - deployed serverless code
  • ▸Trigger - HTTP request that invokes function
  • ▸Environment Variables - secrets or runtime configs
  • ▸Supabase Client - library to interact with database, storage, and auth
  • ▸Supabase CLI - tool for local development and deployment

Official Docs

  • ▸https://supabase.com/docs/guides/functions
  • ▸https://supabase.com/docs/reference/functions

More Supabase-edge-functions Typing Exercises

Simple Supabase Edge Function (TypeScript)Supabase Edge Function Returning JSONSupabase Edge Function with Query ParametersSupabase Edge Function Handling POST RequestSupabase Edge Function Returning HTMLSupabase Edge Function with Custom HeadersSupabase Edge Function Fetching External APISupabase Edge Function Conditional ResponseSupabase Edge Function Redirect

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher