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

koa-spark

v0.4.3

Published

Koa application boilerplate-less

Downloads

9

Readme

KoaSpark - Koa application boilerplate-less

Build Koa applications in a spark.

KoaSpark is a boilerplate-as-a-library for creating Koa apps, it includes out-of-the-box many koa plugins that you normally need for an app like koa-body, koa-cors and koa-router, plus many other useful features like the automatic generation of OpenAPI definitions.

All of this is typically found in templates and boilerplates via cloning a base git repo and then editing it or via a CLI that generates code, this approach works but keep your app updated when a new version of the template is released is a nightmare.

KoaSpark has a differnet approach, it doesn't generate any code, it's just an importable library that provides an alternative to const app = new Koa(): const app = createApp(config, options) and you have a KoaApp ready to use.

Get Started

npm install koa-spark
# or
yarn add koa-spark

Then create the app:

import { createApp } from 'koa-spark'

const app = createApp()

if (require.main === module) {
  app.startServer()
}

Configuration

In Koa Spark, there are 2 levels of configuration, at the app level AppConfig and at the framework level SparkOptions. They are both passed to the createApp(AppConfig, SparkOptions) function.

App Configuration

The app configuration holds environment-specific configurations, like secrets, connection info, etc. that should be changed by the final user if you redistribute the app, or changed when you deploy in production.

The AppConfig can be configured via environmental variables and/or .env files, Koa Spark will automatically initialize the AppConfig properties decorated with @Field() with the corresponding environment variable. Note that AppConfig properties are written in camelCase but env variables are written in UPPER_SNAKE_CASE.

// config.ts
import { AppConfig, Field } from 'koa-spark'

class MyAppConfig extends AppConfig {
  @Field({ default: 'test@localhost' }) // env: FROM_ADDRESS
  fromAddress!: string

  @Field() // env: GCLOUD_STORAGE_BUCKET
  gcloudStorageBucket!: string

  @Field({ default: 'mongodb://localhost/thedb' })
  mongodbConnectionUri!: string

  @Field()
  sendgridApiKey!: string
}

export default new MyAppConfig()

And its relative .env file:

# .env
[email protected]
GCLOUD_STORAGE_BUCKET=my_bucket_production

You can have multiple .env files, one per each environment, named .env.<NODE_ENV>. Koa Spark will try to load the environment-specific file and fallback to the generic one, for example in production will try to load .env.production and if it's missing will load .env.

Framework Options

The framework options SparkOptions are used to configure Koa Spark itself, are more inner-configs than AppConfig, for example they include configurations for CORS, helmet, etc.

As for their nature, framework options are not configurable via env variables, but only via code:

const app = createApp(
  config,
  {
    body: {
      multipart: true
    }
  }
)