Skip to content
Build a serviceDocs 1.3.x

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.

Compose one Connectum server createServer provides the server runtime for your typed RPC handlers, with optional interceptors and protocol plugins. Server runtime createServer · start · stop Your services typed RPC handlers Optional extensions interceptors · protocols
The plates show server composition, not RPC execution order. In-process clients can use registered services before a network listener starts. Lifecycle and shutdown behavior have their own guides below.
Configure, run and stop a server Validated configuration feeds the server lifecycle, while shutdown signals cancellation, drains network connections and executes dependency-ordered hooks before the server stops. ConfigurationValidate and wire options · environment · TLS · shutdown policy Lifecycle and application-owned readiness created startingstart() runningready event stoppingstop() · abort Connection drainNetwork · timeout Shutdown hooksDependency order stoppedNo restart Use the ready / stopping events to update application health explicitly.
Configuration, lifecycle and graceful shutdown own different tasks. The drain timeout does not bound shutdown hooks; in-process cancellation remains cooperative.

Minimal server ​

With your service implementation exported as greeterService:

typescript
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
typescript
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
NeedCanonical destination
Understand states, events, and shutdownSignalLifecycle
Send the server's own messages to your loggerServer log messages
Configure listen address, TLS, environment, or schema extensionConfiguration
Drain requests, coordinate hooks, and fit a deployment deadlineGraceful shutdown
Select HTTP/1.1, h2c, or TLS/ALPN behaviorTransport matrix
Find an exact server option or methodCreateServerOptions 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
bash
npm install @connectum/core
bash
pnpm add @connectum/core
bash
bun add @connectum/core

The 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.