Why Photon
Photon is a next-generation infrastructure for deploying JavaScript servers.
- For users: use any server (Hono, Express.js, Fastify, ...) and deploy anywhere (Cloudflare, Vercel, Netlify, self-hosted, ...).
- For frameworks: easy and incremental Photon integration, with optional tight-knit collaboration.
- For deployment providers: add first-class integration to multiple frameworks at once, with optional tight-knit collaboration.
Features
Photon is jam-packed with features:
- Any server: Hono, Express.js, Elysia, Fastify, H3, Srvx, Hattip.
- Any deployment: Cloudflare, Vercel, self-hosting (e.g. AWS and VPS), and more is work-in-progress.
- HMR: No more full server reload needed.
- Vite Environment API: Develop against production runtimes (e.g. Cloudflare's
workerd). - Code-splitting: Per-route deployment to separate edge workers.
- Zero-config: Integrate your server and deployment with minimal configuration.
- Built-in server: Photon comes with a built-in server for zero-config use (users can use their own instead).
- Bun: First-class support (runs natively through Bun’s
Bun.serve). - Deno: First-class support (runs natively through Deno’s built-in HTTP server).
- Standalone: Self-contained
dist/(nonode_modules/needed), massively reducing disk usage (important for Docker images). - TypeScript: First-class support.
Standalone
With standalone: true, the build output directory (dist/) contains everything needed for deployment. This means that, in production, only the dist/ directory is required (you can remove node_modules/ and skip $ npm install).
Skipping node_modules/ massively reduces disk usage in production, which can be important, for example to reduce the size of Docker images.
It's an advanced feature — more powerful than just using a bundler — and supports:
- Native dependencies.
- File references (e.g.
fs.readFile()).- Multiple versions of the same package.
- All known
node_modules/hierarchies (npm, pnpm, Bun, yarn).It uses Vercel's
nftto trace dependencies, Rolldown to bundle code, while preserving thenode_modules/hierarchy (needed for multiple version support).
HMR
Server-side HMR means that, if you change a server file, the server code is automatically updated: the next HTTP response will be generated by the updated code. No more full server reload required.
This is experimental and doesn't always work: Photon sometimes still triggers a full server reload.
If HMR isn't what you want (for example if you modify the database connection) you can manually trigger a full server reload by pressing r + enter.
Code-splitting
To reduce cold starts, Photon supports server-side code splitting: each page has its own production bundle — each bundle is minimal and contains only what is needed to render that page.
This means you can scale to hundreds of pages while keeping you server cold starts low.
Vite Environment API
Photon's Cloudflare integration uses @cloudflare/vite-plugin, which runs the server-side of the user's app inside workerd — the same runtime Cloudflare Workers uses in production.
This means the development environment is now a faithful representation of Cloudflare's production edge environment.
It's powered by Vite's Environment API, which enables Vite to run in a Node.js process while running the user's server code in another (non-Node.js) process such as
workerd.
Built-in server
By default, Photon uses a built-in server that supports basic features like SSR. If the user needs additional server functionalities (e.g. file uploads), the user can create its own server (Hono/Express.js/...) instead.
Philosophy
Collaboration and a clear separation of concerns are paramount for a thriving ecosystem.
Collaboration
We work with frameworks and deployment providers for full-fledged and seamless integrations while pushing the envelope of what's possible.
Clear separation of concerns
Photon is hyper-focused — we don't re-implement what servers and frameworks already provide.
As a framework or deployment provider, you preserve full control over what makes your framework/deployment special.
We advocate web standards and conventions that foster interoperability beyond Photon and Vite.