kirk

3.0.21 • Public • Published

kirk.js

kirk.js is a framework for node-based applications.

Usage

Create a app.js

This file creates the app object, which can be used everywhere inside your application. It contains the current configuraiton and (depending on the loaded Loaders) the current db connection, express, etc.

app.js

const Kirk = require('kirs.js');

const app = new Kirk();

module.exports = app;
const app = require('./app');

app.start().then(() => {
    console.log('app started.');
});

Note: To enable debugging messages, export DEBUG=kirk:* and run the kirk app.

Controllers

Kirk loads controllers automatically (the location of the controllers is defined with controllerDir).

const app = require('../app');
const controller = new app.Controller();

module.exports = controller;

Loaders

Kirk includes Loaders to load specific parts of the application. It includes the following loaders:

express loader (loaded by default)

This starts an express app and loads all routers (defined in routersDir).

db loader (loaded by default)

This loads all db models (defined in dbModelsDir) and connects to the database. All models are acessable using the global app.db object.

migrations

Migrations are handled per default if there are any (defined in migraitonsDir). The pattern of the filename is /^\d+[\w-]+.js$/ (e.g. 31012017-migration.js). In order to keep the right migration order its good practice to prefix it with the date. During the startup and sync process, kirk automatically loads the all migrations.

The structure of one migration file looks like this:

module.exports = {
    up: function (queryBuilder, Sequelize) {
        return new Promise((resolve, reject) => {
            // do it!
        });
    },

    down: function (queryBuilder, Sequelize) {
        return new Promise((resolve, reject) => {
        });
    }
};

Note: Currently only the up-block is used. There is no automatic rollback, if there are any errors.

pigeon.js loader

This initiates pigeon.

Specify loaders

You can pass the loaders as second argument inside the contstructor:

const app = new Kirk({}, ['pigeon']);

// app.express is not available

app.pigeon.broker.emit(...);

Project structure

As defined inside the config the structure

/project /controllers /db /routers app.js index.js

Options

You can pass the object inside the kirks constructor:

The defaults are:

const app = new Kirk({
    dbModelsDir 'db',               
    routersDir: 'routers',
    controllersDir: 'controllers',

    port: 8080,

    db: { schema: <packageName> }
});
  • dbModelsDir: Specifies the location of the sequelize models.
  • migrationsDir: Specifies the location of database-migrations files.
  • routersDir: Specifies the location of the routers.
  • controllersDir: Specifies the location of the controllers.
  • port: Specifies the express port.

Readme

Keywords

none

Package Sidebar

Install

npm i kirk

Weekly Downloads

5

Version

3.0.21

License

ISC

Last publish

Collaborators

  • becuz
  • manixx
  • s.bider
  • sosedev