koa-base

0.1.7 • Public • Published

koa-base

npm Travis Code Climate Code Climate npm npm

David David

Installation

$ npm install koa-base

Description

This package provides a quick start into the awesome koa framework. It does not tell you how to structure your koa application or which packages you should use. Some basic packages are included out of the box:

Dotenv will search for a .env file, it should contain = separated values which will be put into the process.env object.
.env

PORT=80

This value will be available as:

console.log(process.env.PORT); // 80

Port is the only required value in the .env file!

koa-bodyparser will parse the request for a json body and store it in this.request.body. This is something which most apps will need, that is why this package is included by default.

koa-logger is a development style logger which outputs requests to the console.

koa-static will serve static files out of a directory.

koa-static-cache can be used instead of koa-static to serve static files from memory.

Usage

var koa = require('koa-base');

koa.config = app => {
    // configure app
};

koa.run = server => {
    // if you need the server object for e.g. socket.io
};

// start app, options are not necessary
koa.start({
    port: 80, // default: options.port || process.env.PORT || 80
    serve: 'public', // default: 'public'
    bodyParser: true // default: true
    staticCache: false // default: false
});

Options

  • port will use process.env.PORT or 80 by default
  • serve the directory where static files will be served from (default: public)
  • bodyParser whether json body contents should be parsed (default: true)
  • staticCache enable to serve static files from memory, requires restart to reload files (default: false)

Test

$ npm install -g mocha  
$ mocha

Author

marc1404

License

MIT

Package Sidebar

Install

npm i koa-base

Weekly Downloads

7

Version

0.1.7

License

MIT

Last publish

Collaborators

  • marc1404