Edit this page

Get Started

⚠️ Alpha Stage: Photon is currently in alpha. APIs may change before stable release.

Photon is a next-generation server toolkit designed for library and framework developers who need universal server capabilities.

Who is Photon for?

Photon is primarily designed for:

  • Framework developers building universal web frameworks
  • Library authors creating server-agnostic tools
  • Platform builders needing multi-runtime support
  • Advanced developers who want maximum flexibility

If you're looking to build a simple web app, consider using frameworks built with Photon like Vike instead.

Installation

Install Photon core:

npm install @photonjs/core

Choose a server adapter:

npm install @photonjs/hono

Basic Configuration

// vite.config.ts
import { photon } from '@photonjs/core/vite'
 
export default {
  plugins: [
    photon({
      server: './src/server.ts'
    })
  ]
}

Create Your Server

Choose your preferred server framework. This example shows how to create a universal server that works across runtimes:

With Hono

// src/server.ts
import { Hono } from 'hono'
import { apply, serve } from '@photonjs/hono'
 
const app = new Hono()
 
app.get('/', (c) => c.text('Hello Photon!'))
 
apply(app)
export default serve(app)

With Express

// src/server.ts
import express from 'express'
import { apply, serve } from '@photonjs/express'
 
const app = express()
 
app.get('/', (req, res) => {
  res.send('Hello Photon!')
})
 
apply(app)
export default serve(app)

With Fastify

// src/server.ts
import Fastify from 'fastify'
import { apply, serve } from '@photonjs/fastify'
 
const app = Fastify()
 
app.get('/', async () => {
  return { message: 'Hello Photon!' }
})
 
apply(app)
export default serve(app)

Development

Start the development server:

npm run dev

Your app will be available at http://localhost:3000 with hot module replacement.

Building

Build for production:

npm run build

Building a Framework

If you're building a framework with Photon, consider:

  1. Universal middleware - Create middleware that works across all server adapters
  2. Runtime detection - Handle different deployment targets gracefully
  3. Type safety - Leverage Photon's TypeScript support
  4. Documentation - Help your users understand deployment options

Note: As Photon is in alpha, expect API changes and potential breaking updates. Follow the GitHub repository for the latest developments.