koa-base v0.1.7
koa-base
Installation
$ npm install koa-baseDescription
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=80This value will be available as:
console.log(process.env.PORT); // 80Port 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
portwill useprocess.env.PORTor80by defaultservethe directory where static files will be served from (default:public)bodyParserwhether json body contents should be parsed (default:true)staticCacheenable to serve static files from memory, requires restart to reload files (default:false)
Test
$ npm install -g mocha
$ mocha