-
Notifications
You must be signed in to change notification settings - Fork 4
First T Koa App
Bd999 edited this page Apr 16, 2019
·
4 revisions
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 typescriptNext, 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.jsNow that you open your browser and type localhost:3000, you can see the result.