npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koa-html-template

v1.0.0

Published

This is a koa-based templating engine that can render html files for data rendering.

Readme

koa-html-template
Introduction
  • Koa-html-template makes it easy to render html files
  • Simple operation and simple syntax
Download
npm  i koa-html-template
Instructions
const koa = require("koa")
const Router = require("koa-router")
const Static = require("static-resource-plugin")
// 引入 koa-html-template
const template = require("koa-html-template")

const server = new koa()
const router = new Router()

server.use(Static ()) // The default static folder here is the folder where the static resources are stored.
server.use(template()) // If there is no custom setting to store the path to the html file, it will be stored in the static folder of the project root directory by default.
server.use(router.routes()).use(router.allowedMethods())

router.get("/",async ctx=>{
    ctx.body = "Hello World"
})

router.get("/demo",async ctx=>{
	/*
	* @params path   Path to html template file
	* @params data   The data to be rendered by the template
	* ctx.template(path,data)
	*/
    await ctx.template("html/index.html",{
        demo:"this is a demo page..."
    })
})

server.listen(3000,function(){
    console.log("server is running at http://localhost:3000")
})
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <h2>{{demo}}</h2>
        <br>
        <img src="demo1.jpg" width="300px" alt="">
    </body>
</html>
  • Html file after data rendering
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <h2>this is a demo page...</h2>
        <br>
        <img src="demo1.jpg" width="300px" alt="">
    </body>
</html>

在这里插入图片描述

  • You can see {{demo}} rendered into this is a demo page...
Basic grammar
if statement
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <!-- if statement -->
        {if flag}
        <h1>this is show if statement...</h1>
        {/if}
    </body>
</html>
// server.js
router.get("/demo",async ctx=>{
	/*
	* @params path   Path to html template file
	* @params data   The data to be rendered by the template
	* ctx.template(path,data)
	*/
    await ctx.template("html/index.html",{
        flag:true // the flag is true
    })
})
  • the flag is true 在这里插入图片描述
  • if the flag is false
router.get("/demo",async ctx=>{
    await ctx.template("html/index.html",{
        flag:false // the flag is false
    })
})

在这里插入图片描述

  • You can see that the dom element has disappeared.
for statement
  • If you make a for loop on an array
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        {for list}
        <p>{$index}==>{$value}</p>
        {/for}
    </body>
</html>
// server.js
router.get("/demo",async ctx=>{
    await ctx.template("html/index.html",{
        list:[1,2,3,4]
    })
})

在这里插入图片描述

  • If you are doing a for loop on an object
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        {for list}
        <p>{$key}==>{$value}</p>
        {/for}
    </body>
</html>
// server.js
router.get("/demo",async ctx=>{
    await ctx.template("html/index.html",{
        list:{
			name:"zhangsan",
			age:23,
			gender:"man"
		}
    })
})

在这里插入图片描述

  • If you want a loop on an array containing objects
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        {for list}
        <p>{$value.id}===>{$value.name}</p>
        {/for}
    </body>
</html>
// server.js
router.get("/demo",async ctx=>{
    await ctx.template("html/index.html",{
        list:[
            {
                id:1,
                name:"zhangsan"
            },
            {
                id:2,
                name:"lisi"
            },
            {
                id:3,
                name:"wangwu"
            },
            {
                id:4,
                name:"laowang"
            }
        ]
    })
})

在这里插入图片描述

Support for embedding other html templates
  • Use {-include "othet html path" } to introduce other html templates
<!-- footer.html -->
<h1>this is a footer...</h1>
<p>{{demo}}</p>
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>demo</title>
    </head>
    <body>
        <h1>Hello World</h1>
        {-include "html/footer.html" }
    </body>
</html>
// server.js
router.get("/demo",async ctx=>{
    await ctx.template("html/index.html",{
        demo:"this is a demo page..."
    })
})

在这里插入图片描述

Almost like these