hapi-boilerplate

0.0.1 • Public • Published

hapi-boilerplate

Hapi.js boilerplate

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install hapi-boilerplate --save

Tests

npm install
npm test

Build (production)

npm build

Start (production)

npm start --production

Development

npm run watch # run build and continously watch files for changed and rebuild
npm run server # run server and auto reload when file change
npm run mocha # run all test cases (lighter than "npm test")

Project structure

└ project
  ├ src/                    # <-- Directory contains all source code
  | |
  | ├ components/           # <-- Directory contains all helpers/utilities
  | |                       #     which don't depend on hapi.js
  | | |
  | | ├ config.js           # <-- Helper to load config from config.js file and
  | | |                     #     parse base on NODE_ENV environment variable.
  | | |                     #     Using confidence.
  | | |
  | | ├ knex.js             # <-- Return an instance of knex.
  | | |
  | | ├ orm.js              # <-- Simple module to wrap bookshelf Model to
  | | |                     #     provide some utilities functions like
  | | |                     #     validation.
  | | |
  | | ├ redis.js            # <-- Return an instance of redis. Also provide
  | | |                     #     promise interface.
  | | |
  | | ├ resolveAllOf.js     # <-- Helper to resolve "allOf" in json schema.
  | | |
  | | └ ...
  | |
  | ├ controllers/          # <-- Directory contains all controllers (hapi
  | |                       #     handler functions)
  | |
  | ├ db/                   # <-- Directory contains db configuration,
  | | |                     #     migrations, seed files to work with both
  | | |                     #     application and knex command line.
  | | |
  | | ├ migrations/         # <-- Directory contains migration files. Read
  | | |                     #     knex.js docs for more information.
  | | |
  | | ├ seeds/              # <-- Directory contains seed files. Read knex.js
  | | |                     #     docs for more information.
  | | |
  | | └ knexfile.js         # <-- knex configuration file. Read knex.js docs
  | |                       #     for more information.
  | |
  | ├ models/               # <-- Directory contains all models.
  | |
  | ├ modules/              # <-- Directory contains all modules which work
  | | |                     #     as hapi.js plugin
  | | |
  | | ├ apiLoader.js        # <-- Loader swagger config and generate hapi.js
  | | |                     #     route config.
  | | |
  | | ├ asyncHandler.js     # <-- Hapi.js plugin to help write route handlers
  | | |                     #     using async/await more naturally.
  | | |
  | | └ ...
  | |
  | ├ schemas/              # <-- Directory contains schemas of api & models.
  | | |
  | | ├ api.swagger.yaml    # <-- Root api file, defines all routes here.
  | | |
  | | ├ common.yaml         # <-- Include common parameters for api.
  | | |
  | | └ models/             # <-- Directory contains all models definitions.
  | |   |
  | |   ├ common.yaml       # <-- Include common properties for all models.
  | |   |
  | |   └ ...
  | |
  | ├ config.js             # <-- Application config file, using "confidence".
  | |
  | ├ index.js              # <-- Application entry, contains "main" function,
  | |                       #     load hapi.js server(with plugins) and start.
  | |
  | └ routes.js             # <-- Mapping from swagger operationId to handler
  |                         #     method in controllers.
  |
  ├ test/                   # <-- Directory contains all test files. (Files
  | |                       #     with name "*.spec.js" will be run when test)
  | |
  | ├ common/               # <-- Directory contains some helpers included
  | |                       #     in many test cases.
  | |
  | └ ...
  |
  ├ scripts/                # <-- Directory contains webpack build scripts.
  | |                       #     (Some advanced & confusing shit.)
  | |
  | └ ...
  |
  ├ lib/                    # <-- Auto generated directory contains compiled
  |                         #     library to use in production.
  |
  ├ build/                  # <-- Auto generated directory contains compiled
  |                         #     artifacts for test & dev.
  |
  ├ coverage/               # <-- Auto generated directory contains code
  |                         #     coverage information.
  |
  ├ .babelrc                # <-- Babel configuration file.
  |
  ├ .eslintignore           # <-- ESLint ignore file.
  |
  ├ .eslintrc               # <-- ESLint configuration file.
  |
  ├ index.js                # <-- Entry file. Load in build if NODE_ENV is
  |                         #     "development" or lib if NODE_ENV is "production"
  |
  ├ package.json            # <-- npm configuration file. Contains magic.
  |
  ├ README.md               # <-- This stupid file.
  |
  └  ...

Dependencies

  • bluebird: Full featured Promises/A+ implementation with exceptionally good performance
  • bookshelf: A lightweight ORM for PostgreSQL, MySQL, and SQLite3
  • boom: HTTP-friendly error objects
  • confidence: Configuration API
  • good: Server and process monitoring plugin
  • good-console: Console broadcasting for Good process monitor
  • hapi: HTTP Server framework
  • hapi-swaggered-ui: Easy swagger-ui drop-in plugin for hapi to be used with hapi-swaggered.
  • inert: Static file and directory handlers plugin for hapi.js
  • joi: Object schema validation
  • knex: A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser
  • lodash: Lodash modular utilities.
  • mysql: A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.
  • redis: Redis client library
  • source-map-support: Fixes stack traces for files with source maps
  • sqlite3: Asynchronous, non-blocking SQLite3 bindings
  • swagger-parser: Swagger 2.0 parser and validator for Node and browsers
  • uuid: Rigorous implementation of RFC4122 (v1 and v4) UUIDs.
  • vision: Templates rendering plugin support for hapi.js

Dev Dependencies

License

MIT

Generated by package-json-to-readme

Package Sidebar

Install

npm i hapi-boilerplate

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • yoshisaur