DP-Koa Framework Core
raw JSON →dp-koa-framework-core is a v2 upgrade of the DP-Koa framework core at version 0.1.8, a lightweight, decorator-driven Node.js web framework built on Koa. It enables class-based controllers with decorators for routing (@Get, @Post, @Put, @Del, @All), parameter injection (@Body, @Query, @Params, @State, @Session, @Headers), DTO validation using class-validator, response control (@ResponseCode, @ResponseHeader), HTTP redirects, and an extensible annotation processor system for cross-cutting concerns like logging, authentication, and rate limiting. It supports both legacy and new annotation execution modes switchable via environment variable (USE_NEW_ANNOTATION_SYSTEM=1). Ships TypeScript types. Release cadence is irregular; actively maintained.
Common errors
error Cannot find module 'dp-koa-framework-core' ↓
error TypeError: bindRouter is not a function ↓
error Validation failed for DTO: page must be an integer ↓
Warnings
breaking v2 uses new annotation system by default? Check environment variable USE_NEW_ANNOTATION_SYSTEM. Old system is default (0). Set to 1 to enable processor-based annotation execution. Some decorators may behave differently. ↓
deprecated The old annotation system (default) may be removed in future major versions. Users should migrate to new processor-based system. ↓
gotcha DTO validation requires both class-validator and class-transformer as dependencies. They are not shipped with the package; must be installed separately. ↓
gotcha Do NOT mix named and default imports for decorators. All common decorators (Get, Post, etc.) are named exports only. ↓
breaking The redirect() function returns a special object, not a plain JSON. Ensure your controller returns redirect(...) directly; do not wrap in another object. ↓
Install
npm install dp-koa-framework-core yarn add dp-koa-framework-core pnpm add dp-koa-framework-core Imports
- Get wrong
import { Get } from 'dp-koa-framework-core/decorators'correctimport { Get } from 'dp-koa-framework-core' - bindRouter wrong
const { bindRouter } = require('dp-koa-framework-core')correctimport { bindRouter } from 'dp-koa-framework-core' - bootstrap wrong
import { bootstrap } from 'dp-koa-framework-core/bootstrap'correctimport { bootstrap } from 'dp-koa-framework-core' - MigrationHelper
import { MigrationHelper } from 'dp-koa-framework-core' - router
import { router } from 'dp-koa-framework-core'
Quickstart
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import { bindRouter, router, Get, Query, bootstrap, logger } from 'dp-koa-framework-core';
class HelloController {
@Get('/hello')
async hello(@Query() query: any) {
return { code: 0, data: { message: 'hello', query } };
}
}
async function main() {
const app = new Koa();
app.use(bodyParser());
bindRouter('', HelloController);
app.use(router.routes()).use(router.allowedMethods());
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
app.listen(port, () => logger.info(`listening on :${port}`));
}
main();