Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including koatty with all npm packages installed. Try it out:

var koatty = require("koatty")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koatty v2.6.8

Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.


Koa2 + Typescript = koatty.

Use Typescript's decorator implement IOC and AOP.

Version npmnpm Downloads

New features

  • New: @Scheduled("0 0/1 * * * ?") ✔️ 1.9.2
  • New: replace koa-router to @koa/router ✔️ 1.10.0
  • New: AOP:@Aspect()、@Before()、@After()、@BeforeEach()、@AfterEach() ✔️ 1.11.2
  • New: @Validated: Use class-validator for entity class validation, and support auto create Apidoc. ✔️ 1.12.4
  • New: SchedulerLock is redis-based distributed locks. ✔️ 1.14.8
  • New: @Transactional() with ThinkORM. ✔️ ThinkORM@4.4.8
  • New: think_apollo middleware supports Apollo Configuration Center. ✔️
  • New: bootFunc supports asynchronous. And the appRady/appStart event also supports asynchronous ✔️ 1.15.0
  • New: @CacheAble, @CacheEvict supports redis-based caching ✔️ 1.16.0
  • New: Support asynchronous loading configuration, support plug-in ✔️ 2.5.5
  • New: HTTP/2 ✔️
  • New: koatty for etcd ✔️
  • New: koatty grpc server/client by think_grpc.
  • New: koatty-cloud for trpc/Tars
  • New: koatty-cloud for consul
  • New: koatty-cloud for nacos
  • New: koatty-cloud for SpringCloud
  • New: GraphQL
  • New: SSR


koatty_doc_CN (In progress💪)

[koatty_doc_EN] come soon...


npm i -g koatty_cli

Quick Start

1.Create Project

koatty new projectName

cd ./projectName

yarn install

npm start

2.Create a Controller

koatty controller test

3.Create a Service

koatty service test

3.Create a Middleware (Optional)

koatty middleware test

4.Create a Model(Optional)

Supports thinkorm and typeorm. Please expand other ORM by yourself.

koatty middleware test

koatty middleware -o typeorm test

5.Create a DTOClass (Optional)

koatty dto test

6.Define TestController

import { Controller, BaseController, Autowired, GetMapping, RequestBody, PathVariable, PostMapping, RequestMapping, RequestMethod, Valid } from "koatty";
import { TestDTO } from "../model/dto/TestDTO";
import { TestService } from "../service/TestService";
import { App } from "../App";

export class IndexController extends BaseController {
    app: App;

    private testService: TestService;

    init() {
        this.cache = {};

    @RequestMapping("/", RequestMethod.ALL)
    async default(@PathVariable("test") @Valid("IsNotEmpty") test: string) {
        const info = await this.testService.sayHello().catch((err: any) =>;
        return info;

    @Validated() //need DTOClass
    test(@RequestBody() body: TestDTO) {
        return this.ok("test", body);

How to debug

if you use vscode , edit the .vscode/launch.json , like this:

    "version": "0.2.0",
    "configurations": [
            "type": "node",
            "request": "launch",
            "name": "TS Program",
            "args": [
            "runtimeArgs": [
            "sourceMaps": true,
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "internalConsoleOptions": "neverOpen"

Select TS Program to debug run. Try to call http://localhost:3000/ .


Check out the quick start example.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free