Core Package
Application
The Application class is the main bootstrap class for LaraNode applications. It wraps Express and manages the service provider lifecycle.
Application
The Application class is the main bootstrap class for LaraNode applications. It wraps Express and manages the service provider lifecycle.
Creating an Application
import { Application, Container } from "@lara-node/core";
const container = new Container();
const app = new Application(container);
Registering Providers
app.register(AppServiceProvider);
app.register(RouteServiceProvider);
app.register(CacheServiceProvider);
Booting
await app.boot();
This triggers:
register()on all providersboot()on all providers- Middleware registration
- Express app setup
Starting the Server
// Default port (from config or 3000)
await app.listen();
// Specific port
await app.listen(3000);
// With callback
await app.listen(3000, () => {
console.log("Server started");
});
Accessing Express
const expressApp = app.getExpress();
expressApp.use(cors());
Lifecycle Hooks
// Before booting
app.booting(() => {
console.log("Booting...");
});
// After booting
app.booted(() => {
console.log("Booted!");
});
Global Middleware
app.useGlobalMiddleware(CorsMiddleware);
app.useGlobalMiddleware(RequestLoggerMiddleware);
Complete Example
import { Application, Container } from "@lara-node/core";
import { AppServiceProvider } from "./app/Providers/AppServiceProvider";
import { RouteServiceProvider } from "./app/Providers/RouteServiceProvider";
import "reflect-metadata";
const container = new Container();
const app = new Application(container);
// Register providers
app.register(AppServiceProvider);
app.register(RouteServiceProvider);
// Lifecycle hooks
app.booting(() => {
console.log("Starting application...");
});
app.booted(() => {
console.log("Application booted!");
});
// Boot and start
async function bootstrap() {
await app.boot();
await app.listen(3000);
console.log("Server running on http://localhost:3000");
}
bootstrap();
Next Steps
- Container -- IoC container
- Service Providers -- Creating providers
- Getting Started -- Quick start guide
Core Package
The @lara-node/core package is the foundation of the LaraNode framework. It provides the IoC container, Application bootstrap, Service Provider system, and configuration management.
Configuration (Core)
LaraNode provides a dot-notation configuration system for managing application settings.