3.3.1 • Published 7 years ago

kirk.js v3.3.1

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
7 years ago

kirk.js

This module helps you handling express apps. It loads routers and controllers automatically.

Install

npm install --save kirk.js

Usage

const kirk = require('kirk.js');

kirk.set({ port: 8080 })
.listen()
.then(() => console.info(`started on port ${kirk.config.port}`));

kirk.js loads express routers and controllers automatically and bootstraps an express server. The module relies on actual files and has defaults for the following file structure:

project/
|- controllers/
|- routers/

You can configure the folders using set() (please check the options for that).

set(config:object):object

Sets the main configuration for kirk. You can set the following options:

FieldDefaultDescription
port0The port of the listed express app. 0 means random port.
controllersDirprocess.cwd()/controllersThe location of the controllers.
routersDirprocess.cwd()/routersThe location of the routers.

listen():Promise

This loads the controllers and routers and start the express app. The Promise resolves if the server is running and listed properly.

close():Promise

This shuts down the server (if it was open), and Resolves when everything is done.

Exposed variables

kirk.js exposes the following variables:

FieldDescription
kirk.configThis holds the main configuration (check config for more info)
kirk.appThe actual express app.
kirk.listenerThe listener, which is undefined until listen() is called. It holds the current listener of the server.
kirk.serverThe http service by Node.
kirk.ControllerA generic class for controllers, which extends EventEmitter.

Debug

This module exposes debug messages using the debug module. Just expose DEBUG=kirk and you will get nice debug messages.

Routers

Routers are simple express Routers and you have to export one router per file:

routers/user.js

const router = require('express').Router();

router.get('/', (req, res) => {});
...

router.prefix = '/api/users'
module.exports = router;

You can define a special prefix attribute on the router to prefix all routes easily.

Controllers

Controllers are simple object, which get loaded (using require). Optionally you can extend kirk's controller object, wich is also an EventEmitter.

const controller = new require('kirk.js').Controller();

controller.handleUser = (user, attribute) => {}

module.exports = controller;

Not sure if this actually works, but you get the idea

3.3.1

7 years ago

3.3.0

7 years ago

3.2.9

7 years ago

3.2.8

7 years ago

3.2.7

7 years ago

3.2.6

7 years ago

3.2.5

7 years ago

3.1.5

7 years ago

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago