<commit_before># koa-load-routes
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status](https://coveralls.io/repos/github/gbahamondez/koa-load-routes/badge.svg?branch=master)](https://coveralls.io/github/gbahamondez/koa-load-routes?branch=master)
> [koa@2.x](https://github.com/koajs/koa/tree/v2.x) routes loader from file using [koa-router](https://github.com/alexmingoia/koa-router) module

### Warning
**Node.js 4.0** and **koa@2.x** or latest are requireds  to use this module.


## Installation

```sh
$ npm install --save koa-load-routes
```

## Usage

#### app.js
```js
const Koa = require('koa');
const loader = require('koa-load-routes');

var app = loader(new Koa(), {
  path  : '/routes.js',
  async : false
});


app.listen(3000, function() {
  console.log('server started at http://127.0.0.1:3000/');
});

```

#### routes.js (support generator functions too on koa@2.x)
```js
'use strict';

module.exports = function () {

  this.get('/', function *(next) {
    yield next;
    this.body = 'Im index :D';
  })

  this.get('/hello', function (ctx, next) {
    ctx.body = 'Hello world';
    return next();
  });

};<commit_msg>adding args doc to readme.md<commit_after># koa-load-routes
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status](https://coveralls.io/repos/github/gbahamondez/koa-load-routes/badge.svg?branch=master)](https://coveralls.io/github/gbahamondez/koa-load-routes?branch=master)
> [koa@2.x](https://github.com/koajs/koa/tree/v2.x) routes loader from file using [koa-router](https://github.com/alexmingoia/koa-router) module

### Warning
**Node.js 4.0** and **koa@2.x** or latest are requireds  to use this module.


## Installation

```sh
$ npm install --save koa-load-routes
```

## Usage

#### app.js
```js
const Koa = require('koa');
const loader = require('koa-load-routes');

var app = loader(new Koa(), {
  path  : '/routes.js',
  async : false,
  args  : [304, {name : 'somename'}]
});


app.listen(3000, function() {
  console.log('server started at http://127.0.0.1:3000/');
});

```

#### routes.js (support generator functions too on koa@2.x)
```js
'use strict';

module.exports = function ($status, $body) {

  this.get('/', function *(next) {
    yield next;
    this.status = $status;
    this.body = $body;
  })

  this.get('/hello', function (ctx, next) {
    ctx.body = 'Hello world';
    return next();
  });

};
{'fraction_non_alphanumeric': 0.20797498045347929, 'fraction_numerical': 0.016810007818608287, 'mean_word_length': 4.159274193548387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2666845', 'n_tokens_mistral': 998, 'n_tokens_neox': 954, 'n_words': 190}