4.0.1 • Published 4 years ago

koa-initializer v4.0.1

Weekly downloads
32
License
MIT
Repository
-
Last release
4 years ago

koa-initializer

A koa plugin for handling async/sync initializers of your application.

Installation

npm install koa-initializer

When should I use koa-initializer?

You need to add synchronous or asynchronous code, that must be executed before your koa app starts.

API

const initializer = require('koa-initializer');
const Koa         = require('koa');
const app         = new Koa();

// koa v2

initializer(app)
.then(() => {
    //Your application code
});

// koa v3
await initializer(app);
//Your application code

So as you can see initializer returns promise;

Initializer file path and structure

Your app root folder should contain "initializers" folder with initializers files (name of file irrelevant). initializer.js:

'use strict';

module.exports = {
    priority: 800, // Any diapason (bigger number - higher priority, so 1000 goes before 800)
    execute(app) { // Executable function (takes app as parameter)
        //Any synchronous/asynchronous code (asynchronous must return promise)
    }
};
4.0.1

4 years ago

4.0.0

4 years ago

3.0.2

4 years ago

3.0.1

5 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago