Skip to content

First T Koa App

Bd999 edited this page Apr 16, 2019 · 4 revisions

First T-Koa App

Start

In this chapter, you will learn how to create a T-Koa application.

You need to init a node project and install the latest version of typescript and t-koa first:

$ npm init
$ npm i tkoa
$ npm i typescript

Next, you can create an index.ts file.

And write the following in the index.ts file:

//import tkoa
import tKoa = require('tkoa');

// defined interface
interface ctx {
    response: {
        end: Function
    }
}

const app = new tKoa();

// response
app.use((ctx: ctx) => {
    ctx.response.end('Hello T-koa!');
});

app.listen(3000);

Enter in the terminal:

$ tsc -t es6 -m commonjs index.ts
$ node index.js

Now that you open your browser and type localhost:3000, you can see the result.

Clone this wiki locally