Does Express Work With Cloudflare Pages?
Express can run on Cloudflare Pages via Workers, but it requires an adapter and has cold start/performance trade-offs not ideal for traditional Express apps.
Quick Facts
How Express Works With Cloudflare Pages
Express doesn't natively run on Cloudflare Pages because Pages is a serverless platform optimized for static assets and lightweight functions, while Express is a traditional Node.js server framework. However, you can deploy Express to Cloudflare Pages Functions (which run on Cloudflare Workers) using adapters like `@cloudflare/pages-plugin-express` or by wrapping your Express app to handle the request/response format. The integration works by converting incoming HTTP requests to Express's format and streaming responses back through the Workers runtime. The main trade-off is that Express's traditional stateful server model doesn't align well with serverless's stateless architecture—each request invocation is isolated, and features like in-memory sessions won't persist across requests. This setup is better suited for API backends than for apps relying on server state. For most Express use cases, you'd be better served by native Cloudflare Workers or migrating to a serverless-first framework.
Best Use Cases
Quick Setup
npm install express @cloudflare/pages-plugin-expressimport express from 'express';
import { pages } from '@cloudflare/pages-plugin-express';
const app = express();
app.use(express.json());
app.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from Cloudflare Pages', time: new Date().toISOString() });
});
app.post('/api/data', (req, res) => {
const { name } = req.body;
res.json({ received: name, status: 'ok' });
});
app.use((err, req, res, next) => {
res.status(500).json({ error: err.message });
});
export default pages(app);Known Issues & Gotchas
Express middleware that relies on persistent server state or timers will fail
Fix: Refactor session storage to use external stores (Redis, Durable Objects), remove timer-based middleware, use Cloudflare Durable Objects for stateful operations
Cold starts and request size limits inherited from Workers (10MB body limit)
Fix: Optimize bundle size, implement multipart upload for large payloads, consider native Workers API instead
Some Node.js APIs unavailable in Workers runtime (fs, child_process, native modules)
Fix: Use only web-compatible APIs, rely on Cloudflare services (KV, Durable Objects) for storage, avoid native dependencies
Debugging and local development experience differs from traditional Express server
Fix: Use Wrangler for local testing, familiarize with Workers debugging tools, maintain separate dev/prod configurations
Alternatives
- •Cloudflare Workers with Hono or Elysia – purpose-built serverless frameworks with better DX for edge
- •Next.js or Remix on Cloudflare Pages – full-stack frameworks with native Pages integration and SSR support
- •AWS Lambda with API Gateway – traditional serverless option with broader Node.js ecosystem support
Resources
Related Compatibility Guides
Explore more compatibility guides