AponiaJSDocs
Essentials

Application lifecycle

Start, address, handle, and close an Aponia Elysia application.

Create

const application = await AponiaFactory.create(AppModule);

Creation validates the graph, eagerly constructs singleton providers, registers native plugins, compiles decorated route invokers, and maps controllers.

Pass elysia.aot and elysia.precompile options when route composition should happen during bootstrap instead of on first use. See the Application API.

Listen

const port = Number(Bun.env.PORT ?? 3000);
await application.listen(port);

listen() starts Elysia, waits for its modules, and logs the actual server URL.

Read the URL

console.log(application.getUrl());

getUrl() reads server.url.origin. Calling it before listen() throws an AponiaError with code APPLICATION_NOT_LISTENING.

Handle without a socket

const response = await application.handle(
  new Request("http://localhost/greetings"),
);

This is the preferred HTTP test path.

Close

await application.close();

close() stops the native server when one exists. AponiaJS does not currently provide module/provider lifecycle hook interfaces such as initialization or destruction hooks.

When the Aponia wrapper is unnecessary, AponiaFactory.createNative() returns the composed Elysia instance directly. Native Elysia then owns listen, handle, and stop; see native Elysia access.

On this page