Never Pay for Host Again: Deploy Full-Stack Apps on Cloudflare Pages
Build and deploy production-ready Next.js applications on Cloudflare Pages for free. Learn how to leverage edge computing, database drivers, and server actions without hosting costs.
Never Pay for Host Again: Deploy Full-Stack Apps on Cloudflare Pages
For years, hosting was the elephant in the room for indie developers and startups. You'd build an amazing full-stack application, get ready to launch, and then face the inevitable question: how much will this cost per month?
Then Cloudflare changed the game. With their generous free tier and powerful edge infrastructure, you can now deploy production-grade full-stack Next.js applications without spending a single dollar on hosting.
The Traditional Hosting Dilemma
Traditional hosting has always been expensive for dynamic applications:
- Vercel Pro: $20/month minimum, with variable usage costs
- Netlify: $19/month for basic functions, overages on top
- AWS EC2: $10-50/month just to keep a server running
- DigitalOcean Droplets: $6-40/month depending on specs
- Traditional VPS: $5-20/month baseline, plus you manage everything
Even the "cheap" options add up. That's $120+ annually before you even scale. And if your app gets popular? The overage costs can spike quickly.
Cloudflare Pages: The Game Changer
Cloudflare Pages isn't just a static site host anymore. With support for full-stack frameworks and edge computing, you can build real applications that compete with everything else out there.
Supported Full-Stack Frameworks
Cloudflare works with modern full-stack frameworks that support edge deployment:
- Next.js (with OpenNext)
- Nuxt
- React Router
- Astro
- Qwik
- Solid
Setting Up Next.js on Cloudflare Pages
Getting a Next.js application running on Cloudflare Pages is surprisingly straightforward. Let's walk through the setup:
1. Create Your Project
Start with Cloudflare's CLI (C3) to scaffold a new Next.js project with everything pre-configured:
npm create cloudflare@latest -- my-nextjs-app --framework=nextThis creates a new project with wrangler configuration, OpenNext adapter, and all the necessary setup already in place.
2. Migrate an Existing Next.js App
Already have a Next.js project? No problem. Install the Cloudflare adapter and configure it:
npm install @opennextjs/cloudflareThen install Wrangler as a dev dependency:
npm install -D wrangler@latest3. Configuration Files
Create wrangler.jsonc in your project root:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"main": ".open-next/worker.js",
"name": "my-nextjs-app",
"compatibility_date": "2025-03-25",
"compatibility_flags": [
"nodejs_compat"
],
"assets": {
"directory": ".open-next/assets",
"binding": "ASSETS"
}
}Note: nodejs_compat is essential for running Next.js on Cloudflare Workers.
Create open-next.config.ts for OpenNext configuration:
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
export default defineCloudflareConfig();4. Update package.json Scripts
Add these helpful scripts to your package.json:
{
"scripts": {
"dev": "next dev",
"build": "next build && opennextjs-cloudflare build",
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
"deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
}
}The Edge Computing Advantage
Cloudflare's infrastructure is fundamentally different from traditional hosting. Your code runs on their edge network, which means:
Database Solutions: HTTP Drivers Are Key
The real secret to running full-stack applications on Cloudflare Pages is HTTP-based database access. You don't need traditional socket connections anymore.
Neon: Serverless Postgres (Recommended)
Neon provides a modern serverless PostgreSQL with built-in HTTP drivers—perfect for edge environments.
Query Postgres via HTTP endpoints—no socket connections
Free plan: 100 CU-hours/month, 0.5 GB storage
Point-in-time recovery to recover data instantly
Create database branches for development and testing
For a Next.js app with Drizzle or Prisma, you can use Neon's HTTP driver directly:
// Install the Neon HTTP driver
// npm install @neondatabase/serverless
import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL);
// In a Server Action or API route
export async function getPosts() {
const posts = await sql('SELECT * FROM posts ORDER BY created_at DESC');
return posts;
}Supabase: All-in-One Backend
If you need more than just a database—auth, real-time subscriptions, file storage—Supabase offers it all.
- PostgreSQL database with 500 MB storage
- 50,000 monthly active users for Auth
- 1 GB file storage
- Real-time subscriptions
- Unlimited API requests
Database Comparison Table
Here's how the leading free database options stack up for Cloudflare deployments:
| Feature | Neon | Supabase | Turso |
|---|---|---|---|
| Database Type | PostgreSQL | PostgreSQL | SQLite |
| HTTP Driver | ✓ Native | ✓ REST API | ✓ HTTP |
| Free Storage | 0.5 GB | 500 MB | 500 databases |
| Free Compute | 100 CU-hours | 50K MAUs | Unlimited |
| Auth System | No | ✓ Included | No |
| Branching | ✓ Yes | No | No |
| Real-time | No | ✓ Included | No |
| Best For | Clean DB-first apps | Full backend services | Edge SQLite workloads |
Building with Next.js Server Actions & Edge Functions
Next.js 15 brought incredible features that work perfectly on Cloudflare. Let's explore how to leverage them:
Server Actions on the Edge
Server Actions execute on Cloudflare Workers. They have full access to your database and can handle complex logic:
'use server'
import { neon } from '@neondatabase/serverless'
const sql = neon(process.env.DATABASE_URL)
export async function createPost(title: string, content: string) {
// This runs on Cloudflare edge
const result = await sql(
'INSERT INTO posts (title, content) VALUES ($1, $2) RETURNING *',
[title, content]
)
return result[0]
}API Routes (Route Handlers)
Build REST APIs that run on the edge with the same HTTP database drivers:
// app/api/posts/route.ts
import { neon } from '@neondatabase/serverless'
import { NextResponse } from 'next/server'
const sql = neon(process.env.DATABASE_URL)
export async function GET() {
try {
const posts = await sql('SELECT * FROM posts ORDER BY created_at DESC LIMIT 10')
return NextResponse.json(posts)
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch posts' }, { status: 500 })
}
}
export async function POST(request: Request) {
const { title, content } = await request.json()
try {
const result = await sql(
'INSERT INTO posts (title, content) VALUES ($1, $2) RETURNING *',
[title, content]
)
return NextResponse.json(result[0])
} catch (error) {
return NextResponse.json({ error: 'Failed to create post' }, { status: 500 })
}
}Full-Stack Power
The combination of Next.js + Cloudflare means you can build true full-stack applications:
- Server-side rendering (SSR) with dynamic data
- Real-time updates with revalidation
- Database operations from the edge
- Authentication without third-party services
- Image optimization
- Middleware for authentication and logging
- Incremental Static Regeneration (ISR)
Environment Variables & Secrets
Managing secrets securely on Cloudflare is straightforward using Wrangler:
# Set environment variables for development
# Create a .dev.vars file (local only, not committed)
DATABASE_URL=postgresql://user:password@host/db
API_KEY=your-secret-key
# For production, use Wrangler secrets
wrangler secret put DATABASE_URL
wrangler secret put API_KEY
# Verify secrets are set
wrangler secret listAccess them in your code via process.env:
const databaseUrl = process.env.DATABASE_URL
const apiKey = process.env.API_KEY
// Use them safely in server-side code
export async function getSensitiveData() {
// This only runs on the server, secrets are never exposed
}Comparison: Cloudflare vs Vercel vs Netlify
Let's be real about the cost-benefit analysis:
| Factor | Cloudflare Pages | Vercel | Netlify |
|---|---|---|---|
| Free Tier Cost | $0 | $0 (limited) | $0 (limited) |
| Free Requests/Day | 100,000 | Metered | Metered |
| Pro Plan Cost | Pay-as-you-go | $20/month | $19/month |
| Edge Functions | ✓ Included | ✓ Extra | ✓ Extra |
| Cold Start | Minimal | Good | Good |
| Database Included | No | No | No |
| Developer Experience | Excellent | Excellent | Good |
For a typical indie project with 50,000 requests/month:
$0
Free tier covers it completely
$20+
Pro plan + function invocations
$19+
Pro plan + function hours
That's $240+ annually you save by using Cloudflare instead—money you can reinvest in your product or business.
DevOps Tools to Enhance Your Workflow
When working with Cloudflare, these open-source tools (that I built) make managing your projects much smoother:
CFMAN: Multi-Account Cloudflare Manager
If you're managing multiple Cloudflare accounts (which is common), CFMAN simplifies everything.
Why CFMAN is Essential:
- Switch between accounts without touching environment variables
- Secure token storage—never exposed in shell history
- One command to deploy to any account
- Open source and production-grade
npm install -g cfman
pnpm add -g cfman
yarn global add cfmanLearn more: Visit github.com/novincode/cfman
ENVCF: Sync Environment Variables to Cloudflare
Managing secrets across environments is painful. ENVCF syncs your local environment variables directly to Cloudflare Workers/Pages.
npm install -g envcf
pnpm add -g envcf
yarn global add envcfLearn more: Visit github.com/novincode/envcf
Both tools are designed for developers who value their time and want automation that just works.
Self-Hosting: The Nuclear Option
While Cloudflare is excellent, sometimes you need more control. If you outgrow the free tier or want to self-host, you can still keep costs incredibly low with Docker and a basic Ubuntu server.
Why Self-Host?
- Complete control over your infrastructure
- No vendor lock-in
- Can scale beyond platform limits
- Still incredibly affordable ($5-15/month for VPS)
The Setup: Ubuntu + Docker
Here's how to deploy a Next.js app with Docker on a basic Ubuntu server:
Cost Comparison: VPS Hosting
Popular affordable VPS providers for self-hosting:
$5-6/month (2GB RAM, 1 vCPU)
$5/month (1GB RAM, 1 vCPU)
$2.50-6/month (512MB-2GB RAM)
€3-6/month (2GB-4GB RAM)
The Path Forward
The age of expensive hosting is over. You now have multiple options:
Start Here: Cloudflare Pages
Perfect for MVPs, side projects, and indie apps. Free tier handles 100K requests/day. Scale to paid only when needed.
Growing Project: Upgrade Database
Add Neon Pro plan ($5+) when you need more compute or storage. Cloudflare stays free.
Outgrown Free Tiers: Self-Host
Deploy to Docker on a $5-6 VPS for complete control and predictable costs.
Conclusion
Never paying for hosting isn't just possible—it's the smart choice for indie developers and startups in 2025. Cloudflare's generosity (100K free requests daily), combined with HTTP-based databases and Docker, means you can build and scale production applications without breaking the bank.
The combination of Next.js + Cloudflare Pages + Neon is unbeatable: full-stack capabilities, edge computing, database, and the freedom to never worry about hosting costs until you're making real money.
That's the dream, and it's finally a reality.