koa middleware demo

node v8.17.0
version: 2.0.0
endpointsharetweet
const Koa = require('koa'); const app = new Koa(); // 1 app.use(async (ctx, next) => { console.log('1'); await next(); console.log('1.1'); }); // 2 app.use(async (ctx, next) => { console.log('2'); await next(); console.log('2.1'); }); // 3 app.use(async (ctx, next) => { console.log('3'); await next(); console.log('3.1'); }) // response app.use(async ctx => { ctx.body = 'Hello World'; console.log('Hello World'); }); app.listen(3000);
Created from: https://koajs.com/
Loading…

no comments

    sign in to comment