Migrate an Express Application to Watt
This guide takes an existing Express application and moves it into Watt in stages. Each stage is useful on its own and leaves you with a working application, so you can stop at whichever one gives you what you need.
| Stage | What you change | What you get |
|---|---|---|
| 1. Wrap | Nothing | Watt logging, metrics, management API, wattpm commands |
| 2. Hand over the server | Remove app.listen, export build | Mesh addressing, coordinated startup and shutdown |
| 3. Split | Move code into multiple applications | Isolation, per-application scaling |
Nothing about your routes, middleware, or error handlers changes at any stage. Express stays Express.
The application we are starting from
A typical Express service — routes, a listen call at the bottom, nothing unusual:
// index.js
import express from 'express'
const app = express()
app.get('/health', (req, res) => {
res.json({ status: 'ok' })
})
app.get('/users/:id', (req, res) => {
res.json({ id: req.params.id, name: 'Ada Lovelace' })
})
const port = process.env.PORT ?? 3000
app.listen(port, () => {
console.log(`listening on ${port}`)
})