skills/nodejs-skills/koa/SKILL.md
Provides comprehensive guidance for Koa.js framework including middleware composition, context API, async/await patterns, and application structure. Use when the user asks about Koa, needs to create lightweight Node.js web applications, implement middleware, or build APIs with Koa.
npx skillsauth add partme-ai/full-stack-skills koaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill whenever the user wants to:
ctx and next patterns@koa/router for route definitionsconst Koa = require('koa');
const Router = require('@koa/router');
const bodyParser = require('koa-bodyparser');
const app = new Koa();
const router = new Router();
// Error handling middleware (top of stack)
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
ctx.status = err.status || 500;
ctx.body = { error: err.message };
ctx.app.emit('error', err, ctx);
}
});
// Body parser
app.use(bodyParser());
// Routes
router.get('/api/items', async (ctx) => {
const items = await Item.findAll();
ctx.body = { items };
});
router.post('/api/items', async (ctx) => {
const { name, price } = ctx.request.body;
const item = await Item.create({ name, price });
ctx.status = 201;
ctx.body = item;
});
router.get('/api/items/:id', async (ctx) => {
const item = await Item.findById(ctx.params.id);
if (!item) {
ctx.throw(404, 'Item not found');
}
ctx.body = item;
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000, () => console.log('Server running on port 3000'));
// Logging middleware — demonstrates onion execution order
app.use(async (ctx, next) => {
const start = Date.now();
await next(); // <-- downstream
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
// Authentication middleware
function requireAuth() {
return async (ctx, next) => {
const token = ctx.get('Authorization')?.replace('Bearer ', '');
if (!token) {
ctx.throw(401, 'Authentication required');
}
ctx.state.user = await verifyToken(token);
await next();
};
}
router.get('/api/profile', requireAuth(), async (ctx) => {
ctx.body = ctx.state.user;
});
async/await correctly with next() — always await next() in middlewarectx.throw() for HTTP errors; listen to app.on('error') for logging@koa/cors for CORS configuration; keep middleware chain leankoa, Node.js, middleware, onion model, async/await, context, routing, REST API
development
Provides per-component and per-API examples with cross-platform compatibility details for uni-app, covering built-in components, uni-ui components, and APIs (network, storage, device, UI, navigation, media). Use when the user needs official uni-app components or APIs, wants per-component examples with doc links, or needs platform compatibility checks.
tools
Creates new uni-app projects via the official CLI or HBuilderX with Vue 2/Vue 3 template selection, manifest.json and pages.json configuration, and directory structure setup. Use when the user wants to scaffold a new uni-app project, initialize project files with a single command, or set up the development environment.
tools
Browses, installs, configures, and manages plugins from the uni-app plugin market (ext.dcloud.net.cn) including component plugins, API plugins, and template plugins with dependency handling. Use when the user needs to find and install uni-app plugins, configure plugin settings, manage plugin dependencies, or integrate third-party components.
tools
Develops native Android and iOS plugins for uni-app including module creation, JavaScript-to-native communication, and plugin packaging for distribution. Use when the user needs to build custom native modules, extend uni-app with native capabilities (camera, Bluetooth, sensors), or create publishable native plugins.