New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@commander-lol/koa-mustache

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commander-lol/koa-mustache

Mustache rendering for Koa 2+

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

koa-mustache

Mustache template rendering for Koa 2+

Installation

npm i --save @commander-lol/koa-mustache

Example

const path = require('path')
const Koa = require('koa')
const mustache = require('@commander-lol/koa-mustache')

const app = new Koa()

const templatePath = path.join(__dirname, 'views')
app.use(mustache(templatePath))

// Respond to all requests with the template at `./views/index.mustache`
app.use(async ctx => {
  await ctx.render('index')
})

Usage

  • Require the module const mustache = require('@commander-lol/koa-middleware')
  • Call the function to configure the middleware const middleware = mustache(myTemplateDirectoryPath, myOpts)
  • Mount the middleware on your app app.use(middleware)
  • The ctx.render function has been added to all subsequent middleware (including routes when using routers). await this function to render the specified params to the ctx body. If the template is not found, the status will be set to 404. If the template path is not a regular file, the status will be set to 500.

Types

These are the types that you need to be aware of to use koa-mustache. The export of this module (the object imported by require('@commander-lol/koa-mustache')) is of the type ConfigureMiddleware.

Configuration Options

type Options = {
  debug(...args: any[]): void,
  useCache?: boolean,
  extension?: string,
  partials?: string,
}

Module Export

type ConfigureMiddleware = (root: string, opts?: Options): KoaMiddleware

Render Function

type RenderTemplate = (template: string, data: Object): Promise<void>

Options

nametypedefaultnotes
debugFunctionnoopWill receive debug information. Typically printed with console.log, but could be sent elsewhere
useCachebooleanif NODE_ENV is equal to production, true otherwise falseWill load templates on server boot, and exclusively use the in-memory cache for retrieving templates to render. Partials will always be loaded on boot
extensionstring.mustacheThe file extension to use when loading templates (Must include leading dot)
partialsstringpartialsThe path, relative to the middleware root, where partials are located

Keywords

koa

FAQs

Package last updated on 22 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts