Express Example
A small Express server showing middleware-based permission setup and route protection
Purpose
examples/express is the smallest server-side adapter example in the repository. It demonstrates how to attach Permix to Express, provide request rules, and protect routes with middleware.
What it demonstrates
createPermix()from@aminzoubaa/permix/express- request-scoped setup through
setupMiddleware(...) - route protection with
checkMiddleware(...) - imperative access to the request instance through
permix.get(req, res)
Core idea
Rules are attached to every request before the router runs:
app.use(permix.setupMiddleware(() => ({
user: {
read: true,
write: false,
},
})))Routes can then opt into the required permission:
router.get('/', permix.checkMiddleware('user', 'read'), (req, res) => {
res.send('Hello World')
})Run it
cd examples/express
pnpm startThe server listens on http://localhost:3000.
Key files
main.ts: Express app, adapter setup, and route protection
When to use it
Use this example when you want a server-first integration reference without React, hydration, or client state.