Server
One server owns one process's RPC boundary. Give it your services and any middleware or protocols you need; it owns listening, startup and shutdown.
Minimal server
With your service implementation exported as greeterService:
import { createServer } from '@connectum/core';
import { greeterService } from './services/greeterService.ts';
const server = createServer({ services: [greeterService], port: 5000 });
await server.start();This starts the default HTTP/1.1 listener. Middleware and protocols are explicit additions; native gRPC needs HTTP/2.
Add health, reflection, middleware and shutdown coordination
import { createServer } from '@connectum/core';
import { Healthcheck, healthcheckManager, ServingStatus } from '@connectum/healthcheck';
import { createDefaultInterceptors } from '@connectum/interceptors';
import { Reflection } from '@connectum/reflection';
import { greeterService } from './services/greeterService.ts';
const server = createServer({
services: [greeterService],
port: 5000,
protocols: [Healthcheck({ httpEnabled: true }), Reflection()],
interceptors: createDefaultInterceptors(),
shutdown: { autoShutdown: true, timeout: 30_000 },
});
server.on('ready', () => {
healthcheckManager.update(ServingStatus.SERVING);
});
server.on('stopping', () => {
healthcheckManager.update(ServingStatus.NOT_SERVING);
});
server.on('error', (err) => {
console.error('Server error:', err);
});
await server.start();Starting the server does not automatically set health status to SERVING. See Lifecycle's health-check integration.
Choose the owning guide
Start with lifecycle, configuration or graceful shutdown.
Find an exact server task or API
| Need | Canonical destination |
|---|---|
Understand states, events, and shutdownSignal | Lifecycle |
| Send the server's own messages to your logger | Server log messages |
| Configure listen address, TLS, environment, or schema extension | Configuration |
| Drain requests, coordinate hooks, and fit a deployment deadline | Graceful shutdown |
| Select HTTP/1.1, h2c, or TLS/ALPN behavior | Transport matrix |
| Find an exact server option or method | CreateServerOptions and core API |
The stable state progression is created → starting → running → stopping → stopped. React to lifecycle events for application coordination; pass server.shutdownSignal to long-running work so cancellation follows the same shutdown boundary.
Installation
Add the server foundation to an existing project
npm install @connectum/corepnpm add @connectum/corebun add @connectum/coreThe package shares protobuf and Connect peers with your application. Package managers install missing peers automatically; keep explicit pins in range. createServer() throws PeerDependencyVersionError for an unsupported loaded copy or out-of-lockstep Connect/Connect-node versions; bundling skips that check. See peer requirements for exact ranges.