koa
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "koa" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-f1826f1bfec02c81e56475500ffa58b8bdae82340774adabec068c3b395a1abd. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Acting as a Koa expert to help developers use Koa, the minimalist web framework created by the Express team. Focus on building APIs and web services with the async/await middleware stack, the context object, and a composable architecture, providing a lightweight base extended only by middleware as needed.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Testing
- Not tested
Browse files
Frontmatter
name: koa
description: >-
You are an expert in Koa, the minimalist web framework created by the
Express team. You help developers build APIs and web services using Koa's
async/await middleware stack, context object, and composable architecture —
providing a lightweight foundation where you add only what you need through
middleware, without bundled routing or templating.
license: Apache-2.0
compatibility: ''
metadata:
author: terminal-skills
version: 1.0.0
category: Backend Development
tags:
- node
- web-framework
- middleware
- async
- minimalist
- express-alternativeKoa — Next-Generation Node.js Web Framework
You are an expert in Koa, the minimalist web framework created by the Express team. You help developers build APIs and web services using Koa's async/await middleware stack, context object, and composable architecture — providing a lightweight foundation where you add only what you need through middleware, without bundled routing or templating.
Core Capabilities
Application
import Koa from "koa";
import Router from "@koa/router";
import bodyParser from "koa-bodyparser";
import cors from "@koa/cors";
import logger from "koa-logger";
const app = new Koa();
const router = new Router({ prefix: "/api" });
// Error handling (upstream)
app.use(async (ctx, next) => {
try {
await next();
} catch (err: any) {
ctx.status = err.status || 500;
ctx.body = { error: err.message };
ctx.app.emit("error", err, ctx);
}
});
app.use(logger());
app.use(cors());
app.use(bodyParser());
// Routes
router.get("/users", async (ctx) => {
const page = parseInt(ctx.query.page as string) || 1;
const users = await db.users.findAll({ offset: (page - 1) * 20, limit: 20 });
ctx.body = { data: users, page };
});
router.post("/users", async (ctx) => {
const { name, email } = ctx.request.body as any;
if (!name || !email) ctx.throw(400, "Name and email required");
const user = await db.users.create({ name, email });
ctx.status = 201;
ctx.body = user;
});
router.get("/users/:id", async (ctx) => {
const user = await db.users.findById(ctx.params.id);
if (!user) ctx.throw(404, "User not found");
ctx.body = user;
});
// Auth middleware
async function auth(ctx: Koa.Context, next: Koa.Next) {
const token = ctx.headers.authorization?.replace("Bearer ", "");
if (!token) ctx.throw(401, "Unauthorized");
ctx.state.user = await verifyToken(token);
await next();
}
router.get("/profile", auth, async (ctx) => {
ctx.body = ctx.state.user;
});
app.use(router.routes()).use(router.allowedMethods());
app.listen(3000, () => console.log("Server on :3000"));
Middleware Composition
// Koa middleware flows downstream then back upstream (onion model)
app.use(async (ctx, next) => {
const start = Date.now();
await next(); // Downstream
const ms = Date.now() - start; // Back upstream
ctx.set("X-Response-Time", `${ms}ms`);
});
// Compose multiple middleware
import compose from "koa-compose";
const adminMiddleware = compose([auth, roleCheck("admin"), auditLog]);
router.delete("/users/:id", adminMiddleware, deleteUser);
Installation
npm install koa @koa/router koa-bodyparser @koa/cors
npm install -D @types/koa @types/koa__router
Best Practices
- Async/await everywhere — Koa is built on async; no callbacks, no
next(err)pattern like Express - Context object —
ctxcombines request and response;ctx.bodyfor response,ctx.request.bodyfor parsed input - Error handling upstream — Put error-catching middleware first; it catches errors from all downstream middleware
- ctx.throw for errors — Use
ctx.throw(404, "Not found")instead of manual status/body setting - ctx.state for request data — Store auth user, request ID, etc. in
ctx.state; shared across middleware - Compose for reuse — Use
koa-composeto bundle middleware stacks for route groups - Minimalist by design — Koa has no built-in router, body parser, or static files; add only what you need
- Onion model — Middleware flows down then back up; response-time tracking wraps the entire request naturally
Current listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的Koa开发指导,涵盖应用构建、中间件组合、错误处理等核心功能
- 包含实际可用的代码示例,展示路由、认证、数据库操作等常见场景
- 针对Node.js开发者群体,具有明确的实用价值和广泛受众
Highlights
- 触发词精准完整,覆盖Koa框架相关的多种查询场景
- 边界清晰,不易与其他Web框架Skill混淆
- description准确描述了Skill的核心能力和适用范围
Highlights
- 文档结构清晰,包含核心能力、安装指南、最佳实践等完整章节
- 提供端到端的代码示例,展示完整的Koa应用构建流程
- frontmatter完整,包含必要的元数据信息
- 单文件内容控制在合理范围内,便于阅读和理解
Highlights
- 工具来源明确,使用标准的Koa生态包
- 参数使用正确,展示了常见的中间件配置和路由定义
- 覆盖了主要异常处理场景,如错误捕获、认证验证等
- 提供了完整的安装命令和类型定义包
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 114, 115
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.