This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@ifaxity/koa-json

1.1.0 • Public • Published

@ifaxity/koa-json

A minimal koa@2 pug/html render engine

Minimal dependencies & code is cut down to not take so much space. Because node_modules hell is something i want to avoid. This module was for private purposes but making it public wont do any harm.

Code heavily based on the koa-views package


Installation:

npm install @ifaxity/koa-json --save

or if you use yarn

yarn add @ifaxity/koa-json


Usage

To use the module just require it like this

const jwt = require('@ifaxity/koa-json');

And then you need to add it to your koa server like this:

const render = require('@ifaxity/koa-json');

// or whatever folder you use for your views
app.use(render(__dirname + '/views'), {
  ext: 'pug',
  globals: {
    title: 'Default title',
  }
});


// Example route
app.use(async ctx => {
  // Render state object
  ctx.state = {
    title: 'Index page title',
  };

  await ctx.render('index', {
    foo: 'bar',
  });
});

// You can also switch between .pug and .html files like this
// As the option 'ext' only specifies the default extension
app.use(async ctx => {
  await ctx.render('index.html');
});

Readme

Keywords

none

Package Sidebar

Install

npm i @ifaxity/koa-json

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

4.82 kB

Total Files

5

Last publish

Collaborators

  • ifaxity