App
An App is a collection of Modules. It is the entry point of your application.
Usage
- npm
- Bun
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
index.ts
import * as pg from "pg";
import { PostgresDB } from "@tymber/postgres";
import { App } from "@tymber/core";
import { MyModule } from "./my-module";
import { AdminModule } from "@tymber/admin";
const pgPool = new pg.Pool({
user: "postgres",
password: "changeit",
});
const db = new PostgresDB(pgPool);
const app = await App.create({
components: [db],
modules: [
AdminModule,
MyModule,
],
});
export default {
port: 8080,
fetch: app.fetch,
};
And then:
bun 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();
});