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 🙏

© 2024 – Pkg Stats / Ryan Hefner

init-koa2

v1.0.1

Published

Have your new koa2 project ready for development with all necessary modules

Downloads

3

Readme

npm license GitHub issues Gitter GitHub stars

Introduction

init-koa2 is a WIP effort to automate the process of developing a new project with Koa2.

Usually when starting a new Koa app, you'll go through the regular routine of:

  1. adding plenty packages like koa-bodyparser, koa-router, koa-bunyan-logger, ...etc
  2. Setting up constants.
  3. Wiring babel.
  4. ... and much more tedious steps in order to actually start working.

This is a needed node module

Koa is bare-bones (compared to express for instance), it's extremely fast, but with the cost of loosing a lot of default packages that are almost needed in every project.

This is a good thing, it allows you to use the packages you need, for the functionality you need, but this process takes time, and requires a effort and great attention to have your Koa app initialized properly.

Convention over configuration

What this package does, is basically this:

// index.js
require('init-koa2')({
  port: 3000,
  useStaticFiles: {
    dir: 'public',
    maxage: 0,
    hidden: false,
    index: 'index.json'
  },
  useBodyParser: {
    enableTypes: [ 'json' ],
    encode: 'utf8',
    jsonLimit: '1mb',
    strict: 'true'
  },
  useKoaRouter: true
});

router.get('home', '/', (ctx, next) => {
  ctx.body = 'Hello World!';
});

So it'll basically allow you to include packages only when you configure them, while having default configs of course.

In the above example, if you don't configure koa-router, then it's not included in your app, if you do, then it's included. That's it.

No need to define and require Koa itself, or the other basic packages like router, bodyparse, ... etc

This module is starting with the minimum basic packages to get up and running with a Koa2 app to build REST APIs, GraphQL server, or a regular Web App running React.

So you can expect support for packages like router, bodyparser, graphql, graphi, ..etc all optional, all configurable, no need for installing and requiring each one individually, just start with your new project with require('init-koa2')({Object}: options).

Usage:

This module currently make use of the following submodules:

  • "koa-router": "^7.0.1"
  • "koa-static": "^2.0.0"
  • "koa-bunyan-logger": "^1.3.0"
  • "koa-bodyparser": "^3.2.0"

Init

All you need to do in order to initialize your Koa app is to add this require on top of your entry file.

Example:

const init = require('init-koa2');
init();

Or shorter:

require('init-koa2')();

Then just run your app, no need to add anything else, for example, don't do app = new Koa(); or app.listen(port) because all of this was done for you already.

Configuring sub-modules:

Optionally you can configure the above packages like so require('init-koa2')({ options });

Available options:

port:

Application port (Default: 3000)

logging:

Enable or disable logs (Default: true)

useStaticFiles:

Enable/Disable serving static files

Docs: https://www.npmjs.com/package/koa-static#options

Default:

{
  dir: 'public',
  maxage: 0,
  hidden: false,
  index: 'index.json'
}

useBodyParser: Enable/disable bodyparser (Default: enableTypes: [ 'json' ], encode: 'utf8', jsonLimit: '1mb', strict: 'true' })

useEslint:

Not yet available, coming in release 1.1.0.

useBunyanLogger: Enable/Disable logging for REST requests/respones

Docs: https://www.npmjs.com/package/koa-bunyan-logger

Default: true

Not configurable, can only be enabled or disabled.

useKoaRouter: Enable/Disable routing

Docs: https://github.com/alexmingoia/koa-router/tree/master/

Default: true

Not configurable, can only be enabled or disabled. If you want this to be configurable, please file an issue.

autoInitiateKoa:

Automatically initiate koa app instance, and automatically start the app and listen to the pre-defined port.

Not configurable, always set to true. If you want this to be configurable, please file an issue.

Ultimate goal:

This project's ultimate goal is to have the development with Koa so easy to start with, whenever you start writing a Koa app, you should just start writing it, not waste a lot of time configuring, and setting up in order to begin actually developing.

Everything should be ready, and manageable from the first minute.

@TODO (Release 1.0.0)

  • [x] Complete wiring up the remaining core packages.

@TODO (Release 1.1.0)

  • [ ] Add support for adding & configuring ESlint.

@TODO (Release 2.0.0)

  • [ ] Adding support for using & configuring Babel.

@TODO (Release x.0.0)

  • [ ] Adding support for using & configuring React.
  • [ ] Adding support for using & configuring GraphQL.