The createElysiaApplication function initializes the root module and returns an Elysia instance ready to listen for requests.
Basic Usage
typescript
import { createElysiaApplication } from "nestelia";
const app = await createElysiaApplication(AppModule);
app.listen(3000);What createElysiaApplication Does
- Resolves the module tree — processes imports, providers, and controllers recursively
- Registers providers — adds all providers to the DI container
- Instantiates controllers — creates controller instances with dependencies injected
- Registers routes — maps decorated methods to Elysia routes
- Runs lifecycle hooks — calls
onModuleInitandonApplicationBootstrapin order - Returns an ElysiaNestApplication — ready to call
.listen()
With Microservices
When using the microservices package, createElysiaApplication returns an ElysiaNestApplication that supports hybrid HTTP + microservice mode:
typescript
import { createElysiaApplication } from "nestelia";
import { Transport } from "nestelia/microservices";
const app = await createElysiaApplication(AppModule);
app.connectMicroservice({
transport: Transport.REDIS,
options: { host: "localhost", port: 6379 },
});
await app.startAllMicroservices();
app.listen(3000);Graceful Shutdown
nestelia supports shutdown lifecycle hooks. When the process receives a termination signal:
BeforeApplicationShutdownhooks run firstOnModuleDestroyhooks run for cleanupOnApplicationShutdownhooks run last
typescript
@Injectable()
class DatabaseService implements OnModuleDestroy {
async onModuleDestroy() {
await this.connection.close();
}
}