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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mpecarina/koa-template

v2.0.2

Published

koa typescript template

Downloads

14

Readme

koa-template

install package:

yarn add @mpecarina/koa-template

import and use:

src/index.ts

import { initApps, logger, bodyParser, json, koaRouter } from "@mpecarina/koa-template"
import path from "path"

const { NODE_ENV, APP_PORT_0, APP_PORT_1 } = process.env
const postmanProxyRoutes = path.join(__dirname, `../service_definitions/postman-echo-routes-${NODE_ENV}.yaml`)

const [app, metricsApp] = initApps([
  logger(),
  bodyParser(),
  json({ pretty: false, param: "pretty", spaces: 2 }),
  koaRouter(postmanProxyRoutes),
])

app.listen(APP_PORT_0 || 3000)
metricsApp.listen(APP_PORT_1 || 3001)

example postman echo proxy service definition

service_definitions/postman-echo-routes-test.yaml

- name: postman-echo
  origin:
    - localhost
    - "localhost:3000"
  description: ""
  controller: ""
  handler: ""
  routes:
    - "/:path*"
  method:
    - get
    - post
    - put
    - patch
    - delete
    - trace
    - options
  proxy:
    enabled: true
    raw: true
    redirect: false
    url: https://postman-echo.com
    filter:
      enabled: true
      find: https://postman-echo.com
      replace: http://localhost:3000
      fields:
        - url

default handler function in health-check controller

src/controllers/health-check.ts

/* eslint-disable no-unused-vars */
import { BaseContext } from "koa"

export const ping = async (ctx: BaseContext) => {
  ctx.status = 200
  ctx.body = { status: "success", msg: "pong" }
}

call the postman echo get route

http://localhost:3000/get?foo=bar

{"args":{"foo":"bar"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f4aaefe-fd51ab6c267499c8a63b245c","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","cache-control":"max-age=0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36","sec-fetch-site":"none","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9","cookie":"_ga=GA1.1.54043150.1593003926; hubspotutk=5a444a8d8277c6687ed5d5f5b3ce1663; __hstc=181257784.5a444a8d8277c6687ed5d5f5b3ce1663.1597153074511.1597153074511.1597167095022.2","api-gateway-request-id":"dbe75cd4-cf19-455f-83c5-69803d61d8c9"},"url":"http://localhost:3000/get?foo=bar"}

call the postman echo post route

curl -X POST http://localhost:3000/post -d '{"foo":"bar"}'
{"args":{},"data":"","files":{},"form":{"{\"{\\\"foo\\\":\\\"bar\\\"}\":\"\"}":""},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f4ab3d9-6073737a7349d6e2e223e432","content-length":"24","accept":"*/*","content-type":"application/x-www-form-urlencoded","user-agent":"curl/7.64.1","api-gateway-request-id":"d6d8b733-29e6-4011-a82c-53e9aa69b289"},"json":{"{\"{\\\"foo\\\":\\\"bar\\\"}\":\"\"}":""},"url":"http://localhost:3000/post"}

call the health check route

curl http://localhost:3000/health/ping
{"status":"success","msg":"pong"}

create a new hello world handler function in example controller

src/controllers/example.ts

/* eslint-disable no-unused-vars */
import { BaseContext } from "koa"

export const hello = async (ctx: BaseContext) => {
  ctx.status = 200
  ctx.body = { status: "success", msg: `hello ${ctx.query.name || "world"}` }
}

create new service definition for hello world route

- name: hello-world
  origin:
    - "127.0.0.1"
    - "127.0.0.1:3000"
  controller: "example"
  handler: "hello"
  routes:
    - "/example/hello"
  method:
    - get
  proxy:
    enabled: false

update the application to use new route

src/index.ts

import { initApps, logger, bodyParser, json, koaRouter } from "@mpecarina/koa-template"
import path from "path"

const { NODE_ENV, APP_PORT_0, APP_PORT_1 } = process.env
const postmanProxyRoutes = path.join(__dirname, `../service_definitions/postman-echo-routes-${NODE_ENV}.yaml`)
const exampleHelloRoutes = path.join(__dirname, `../service_definitions/example-hello-routes-${NODE_ENV}.yaml`)
const exampleControllers = path.join(__dirname, `./controllers`)

const [app, metricsApp] = initApps([
  logger(),
  bodyParser(),
  json({ pretty: false, param: "pretty", spaces: 2 }),
  koaRouter(postmanProxyRoutes),
  koaRouter(exampleHelloRoutes, exampleControllers),
])

app.listen(APP_PORT_0 || 3000)
metricsApp.listen(APP_PORT_1 || 3001)

call new hello world handler function

http://127.0.0.1:3000/example/hello

{"status":"success","msg":"hello world"}

http://127.0.0.1:3000/example/hello?name=bob

{"status":"success","msg":"hello bob"}

example api-gateway application

https://github.com/mpecarina/api-gateway