misho85 / koa-api-boilerplate

Babel removed as a dependency: Boilerplate for building APIs with koa2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-api-boilerplate

js-standard-style Coverage Status semantic-release Greenkeeper badge

This repository is a boilerplate for building APIs with koa2 and Mongo DB. This repository was originally forked from Adrian Obelmejias' koa-api-boilerplate repository. It makes the following modifications:

  • Removes babel as a dependency. This repository is now naively compatible with node v8.9 or higher.

  • Replaced bcrypt dependency with bcryptjs. This improves compatibility across versions of node.js and across OSs.

  • Configured for Travis CI (continuous integration), Coveralls (code coverage), Green Keeper (automated dependency management), and Semantic Release (automated versioning).

  • 'Production' environment is targeted for packaging as a Docker container.

  • 'admin' user type added in addition to standard 'user' type. Allows the creation of private vs public APIs that only be accessed by an admin. Useful for privileged commands like updating and deleting other users.

  • Winston logging integrated for daily rotated logs and a maximum size of 1 megabyte.

Features

This project covers basic necessities of most APIs.

  • Authentication (passport & jwt)
  • Database (mongoose)
  • Testing (mocha)
  • Doc generation with apidoc
  • Linting using standard
  • Packaged as a Docker container

Requirements

  • node ^10.15.1
  • npm ^6.7.0

Installation

git clone https://github.com/christroutner/koa-api-boilerplate
cd koa-api-boilerplate
npm install
npm start

Structure

├── bin
│   └── server.js            # Bootstrapping and entry point
├── config                   # Server configuration settings
│   ├── env                  # Environment specific config
│   │   ├── common.js
│   │   ├── development.js
│   │   ├── production.js
│   │   └── test.js
│   ├── index.js             # Config entrypoint - exports config according to envionrment and commons
│   └── passport.js          # Passportjs config of strategies
|
├── production               # Dockerfile for build production container
|
├── src                      # Source code
│   ├── lib                  # Business logic libraries
│   ├── modules
│   │   ├── controller.js    # Module-specific controllers
│   │   └── router.js        # Router definitions for module
│   ├── models               # Mongoose models
│   └── middleware           # Custom middleware
│       └── validators       # Validation middleware
└── test                     # Unit tests

Usage

  • npm start Start server on live mode
  • npm run dev Start server on dev mode with nodemon
  • npm run docs Generate API documentation
  • npm test Run mocha tests
  • docker-compose build Build a 'production' Docker container
  • docker-compose up Run the docker container

Documentation

API documentation is written inline and generated by apidoc.

Visit http://localhost:5000/docs/ to view docs

Dependencies

IPFS

v2.3.0 uploaded to IPFS:

  • Get it: ipfs get QmUz4b2KwNLNvHZRTYcgrPCuKAhMB73XWN8vY8LLVVEYV1
  • Pin it: ipfs pin add -r QmUz4b2KwNLNvHZRTYcgrPCuKAhMB73XWN8vY8LLVVEYV1

License

MIT

About

Babel removed as a dependency: Boilerplate for building APIs with koa2.

License:MIT License


Languages

Language:JavaScript 91.9%Language:HTML 5.4%Language:Dockerfile 2.2%Language:Shell 0.5%