koa views - Tuong-Nguyen/JavaScript-Structure GitHub Wiki

Koa-views (https://github.com/queckezz/koa-views)

koa-views is a template rendering middleware; ex: pug -> html It supports multiple engines: pug, handlebar, swig, ...

Use

const views = require('koa-views');

// Add koa-views middleware
app.use(views(__dirname + '/views', {
  map: {
    // use pug engine for file with html extension
    html: 'pug'
  }
}));

// render `user.html` with pug
app.use(async function (ctx) {
  await ctx.render('user.html')
})

Note: beside koa-views, we need to install template engine ex: pug. (npm install --save koa-views pug)