Skip to main content

App

An App is a collection of Modules. It is the entry point of your application.

Usage

index.ts
import * as pg from "pg";
import { PostgresDB } from "@tymber/postgres";
import { App, toNodeHandler } from "@tymber/core";
import { AdminModule } from "@tymber/admin";
import { MyModule } from "./my-module";
import { createServer } from "node:http";

const pgPool = new pg.Pool({
user: "postgres",
password: "changeit",
});

const db = new PostgresDB(pgPool);

const app = await App.create({
components: [db],
modules: [
AdminModule,
MyModule,
]
});

const httpServer = createServer(toNodeHandler(app.fetch));

httpServer.listen(8080);

And then with tsx:

npx tsx index.ts

The components arguments allows providing already instantiated components, like a database pool.

Shutdown

The application can be cleanly shut down by calling app.close():

process.on("SIGTERM", async () => {
await app.close();
});