CTRL K
API Reference
1 min read
API Reference
Complete reference for all available methods and configurations.
Methods
init(options)
Initialize the application with the given options.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
options | Object | No | Configuration options |
options.name | string | Yes | Project name |
options.debug | boolean | No | Enable debug mode |
Returns: Promise<App>
Example:
const app = await init({
name: "my-app",
debug: true
});start(port)
Start the server on the specified port.
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
port | number | No | 3000 | Port number |
Returns: Promise<Server>
Example:
const server = await app.start(8080);
console.log("Server running on port 8080");stop()
Gracefully stop the server.
Returns: Promise<void>
Example:
await app.stop();
console.log("Server stopped");Events
on(event, callback)
Register an event listener.
Available Events:
start- Fired when server startsstop- Fired when server stopserror- Fired on errorrequest- Fired on each request
Example:
app.on("start", () => {
console.log("Server started!");
});
app.on("error", (err) => {
console.error("Error:", err.message);
});Configuration
Config Object
interface Config {
// Required
name: string;
// Optional
version?: string;
debug?: boolean;
port?: number;
// Advanced
middleware?: Function[];
plugins?: Plugin[];
// Logging
logging?: {
level: "debug" | "info" | "warn" | "error";
format: "json" | "text";
};
}Environment Variables
| Variable | Description | Default |
|---|---|---|
APP_NAME | Application name | - |
APP_PORT | Server port | 3000 |
APP_DEBUG | Debug mode | false |
LOG_LEVEL | Logging level | info |
Error Codes
| Code | Name | Description |
|---|---|---|
E001 | InitError | Initialization failed |
E002 | ConfigError | Invalid configuration |
E003 | PortError | Port already in use |
E004 | TimeoutError | Operation timed out |
For more help, check the Introduction.