Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-view

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-view

koa view use nunjucks

  • 2.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
189
decreased by-32.98%
Maintainers
2
Weekly downloads
 
Created
Source

koa-view

NPM version Dependency Status Build Status Coverage Status Greenkeeper badge

Template rendering middleware for koa (using nunjucks).

Installation

$ npm install koa-view

Example

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

// Must be used before any router is used
app.use(view(__dirname + '/views'));

app.use(async function (ctx) {
  ctx.state = {
    session: ctx.session,
    title: 'app'
  };

  await ctx.render('user', {
    user: 'Coder'
  });
});

More examples: tests

API

view(root, opts)
  • root: (default views) Views location. All view you render() are relative to this path.
  • opts nunjucks configure opts
  • opts.ext: (default html) Extension for your view
// instead of this
await ctx.render('user.html')
// you can
await ctx.render('user')

Koa 1 Support

To use koa-view with koa@1, please use koa-view 1.x.

npm install koa-view@1 --save

License

MIT

Keywords

FAQs

Package last updated on 16 Jul 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc