hapiboot

0.2.2 • Public • Published

HapiBoot

HapiBoot is a small helper library to load modules when you have a large and structured Api.

HapiBoot loads your modules from a given path and registers them as plugins. So you can easily structure your api and manage dependencies.

Install

npm install hapiboot --save

Setup

Modify your hapi start

//Load HAPI
let Hapi = require('hapi');


//Load HapiBoot
let Boot = require('hapiboot');

//Create server
const server = new Hapi.Server();

//Instantiate hapiBoot
let hapiBoot = new Boot(server, require('./config/boot.json'));

// start hapiBoot
hapiBoot.boot();

// Default hapi config and startup
server.connection({
    host: 'localhost',
    port: process.env.PORT || 3000
});

server.on('log', (event, tags) => {
    console.log(event.data);
});

// Start the server
server.start((err) => {
    if (err) throw err;
    server.log(['info', 'debug'],'Server running at: '+server.info.uri);
});

Config

Create the config file boot.json

{
  "api" : {
    "root" : "api/modules", //Define where your modules are located
  },
  "modules":[ //Define which modules should be loaded
      "helloWorldModule"
  ]
}

Package Sidebar

Install

npm i hapiboot

Weekly Downloads

1

Version

0.2.2

License

ISC

Last publish

Collaborators

  • faebeee