Kontas Web Framework for Bun
raw JSON →Kontas is a minimalist and high-performance web framework designed specifically for the Bun JavaScript runtime. Currently at version 0.1.149, it focuses on providing a simple, Koa-style asynchronous middleware pipeline and routing for building web applications with Bun. Its core differentiator lies in its commitment to simplicity, speed, and native Bun integration, leveraging Bun's fast JavaScriptCore engine and built-in Web API compatibility. While its pre-1.0 version suggests a rapid release cadence with potential API evolution, Kontas aims to offer an elegant, developer-friendly experience for backend development, contrasting with more opinionated or heavier frameworks. It's ideal for projects prioritizing raw performance and a lightweight footprint within the Bun ecosystem, offering an alternative to frameworks like Elysia or Hono by emphasizing minimalism.
Common errors
error ReferenceError: require is not defined in ES module scope ↓
const Kontas = require('kontas'); with import Kontas from 'kontas';. Ensure all local files are also using ESM syntax or have .cts / .mts extensions if mixed modules are strictly necessary. error Error: Port 3000 is already in use ↓
app.listen(PORT, ...) to an available one (e.g., 8000), or terminate the process currently using the port (lsof -i :3000 on macOS/Linux, then kill <PID>). error TypeError: Cannot read properties of undefined (reading 'response') ↓
Context object. Verify the Context type definition and object structure in the Kontas documentation. Explicitly type ctx: Context to catch issues at compile-time. Warnings
breaking As a 0.x.x version package, Kontas's API is subject to frequent and significant breaking changes without major version bumps. Always pin exact versions in `package.json` and review changelogs diligently. ↓
gotcha Kontas is built exclusively for Bun. It will not run on Node.js, Deno, or in a browser environment due to its reliance on Bun's specific runtime APIs and `Bun.serve` underneath. ↓
gotcha Error handling might differ from other popular web frameworks (e.g., Express, Koa). Understand Kontas's specific error propagation mechanism to prevent unhandled exceptions or unexpected responses. ↓
gotcha Body parsing for POST/PUT requests is not always built-in by default in minimalist frameworks. You might need to add specific middleware or handle it manually. ↓
Install
npm install kontas yarn add kontas pnpm add kontas Imports
- Kontas wrong
const Kontas = require('kontas');correctimport Kontas from 'kontas'; - Context
import type { Context } from 'kontas'; - Middleware
import type { Middleware } from 'kontas';
Quickstart
import Kontas from 'kontas';
import type { Context } from 'kontas';
const app = new Kontas();
const PORT = 3000;
// Basic GET route
app.get('/', (ctx: Context) => {
return ctx.response.text('Hello, Kontas!');
});
// Route with a path parameter
app.get('/users/:id', (ctx: Context) => {
const userId = ctx.params.id;
return ctx.response.json({ message: `Fetching user ${userId}` });
});
// Middleware example
app.use((ctx: Context, next: () => Promise<void>) => {
console.log(`[${new Date().toISOString()}] Request received: ${ctx.request.url}`);
return next();
});
// Start the server
app.listen(PORT, () => {
console.log(`Kontas server running on http://localhost:${PORT}`);
console.log('Try visiting / and /users/123');
});