@openreachtech/renchan-express
v0.2.1
Published
Express bindings for renchan
Keywords
Readme
@openreachtech/renchan-express
Express bindings for renchan: route classes, and a server builder that assembles an Express application out of an engine and a server-specific routes builder.
Concept
A server built on this package is split into three parts.
| part | responsibility | provided by |
| :-- | :-- | :-- |
| engine | holds the environment and the config, and collects the middleware and the Express settings | BaseServerEngine, derived by the application |
| server-specific routes builder | produces the routes the server answers on | BaseServerSpecificRoutesBuilder, derived by the application. SentinelServerSpecificRoutesBuilder for a server with no routes of its own |
| server builder | assembles the two into an Express application and an HTTP server | BaseExpressServerBuilder, derived by the application |
What kind of server it is — JSON-RPC, RESTful API, GraphQL — is settled by the server-specific routes builder a derived server builder names. The server builder itself knows nothing about it.
Each dependency is reached through the classes listed below, so that a major version of one is answered in those classes alone.
| dependency | reached through |
| :-- | :-- |
| express | BaseExpressServerBuilder, BaseExpressMiddlewareInflator |
| http | BaseExpressServerBuilder |
| cors | CorsMiddlewareInflator |
Installation
Requires Node.js 24.19.0 or later (the CI builds against the current LTS).
npm install @openreachtech/renchan-expressIt is an ES module ("type": "module"); import it with ESM import syntax.
The following are peer dependencies. The application provides them.
| package | range |
| :-- | :-- |
| express | ^4.22.3 |
| @types/express | ^4.17.25 |
| cors | ^2.8.6 |
| @types/cors | ^2.8.19 |
Usage
import {
BaseServerSpecificRoutesBuilder,
BaseExpressServerBuilder,
BaseServerEngine,
GetMethodExpressRoute,
} from '@openreachtech/renchan-express'
// The engine: config, middleware and Express settings.
class AlphaServerEngine extends BaseServerEngine {
static get env () {
return {
NODE_ENV: 'development',
}
}
static get config () {
return {
staticPath: 'public/',
}
}
composeMiddlewareFactoryOptionsLookup () {
return {
static: [this.config.staticPath],
json: [{ limit: '10mb' }],
}
}
collectExpressSettings () {
return {
'trust proxy': true,
}
}
}
// The server-specific routes builder: the routes the server answers on.
class AlphaServerSpecificRoutesBuilder extends BaseServerSpecificRoutesBuilder {
buildRoutes () {
return [
GetMethodExpressRoute.create({
path: '/health',
handlers: [
(req, res) => {
res.json({
status: 'ok',
})
},
],
}),
]
}
}
// The server builder: names the server-specific routes builder, and nothing else.
class AlphaExpressServerBuilder extends BaseExpressServerBuilder {
static get ServerSpecificRoutesBuilderCtor () {
return AlphaServerSpecificRoutesBuilder
}
}
const serverBuilder = await AlphaExpressServerBuilder.createAsync({
EngineCtor: AlphaServerEngine,
})
serverBuilder.buildHttpServer()
.listen(3000)The engine is derived from BaseServerEngine, and the server-specific routes builder from BaseServerSpecificRoutesBuilder.
A server whose engine carries every middleware it needs has no routes to build. Such a server names SentinelServerSpecificRoutesBuilder, which builds no routes, as its server-specific routes builder.
API
How the server is assembled
#buildHttpServer() runs the following steps in order.
- Apply the settings the engine collects to the Express application. Express reads its settings when the first route is mounted, so this comes before any mounting.
- Collect one middleware route carrying every handler the engine collects.
- Collect the routes the server-specific routes builder produces.
- Mount the middleware route, then the other routes, onto the Express application.
- Hand the mounted application to
#buildServerRootApp(), which returns it unchanged unless a derived class overrides it. - Create an HTTP server from what step 5 returns. The server is returned without listening.
Contribution
Bug reports, feature requests, and code contributions are welcome.
Feel free to contact us through GitHub Issues.
git clone https://github.com/openreachtech/renchan-express.git
cd renchan-express
npm install
npm run lint
npm testLicense
This project is released under the Apache License 2.0.
For more details, please see in the LICENSE file.
Developer
Copyright
© 2026 Open Reach Tech Inc.
