Skip to content

There are many node service boilerplates, but this one is mine.

Notifications You must be signed in to change notification settings

batjko/api-boilerplate

Repository files navigation

Pat's API boilerplate

js-standard-style CI Status

Shit included:

  1. Fastify as the API server (fast and comes with Pino out of the box)
  2. AVA and supertest for testing
  3. Flow for totally optional type annotations
  4. Standardjs and Prettier for never-think-of-it-again code formatting

Design

The thing is designed to be simple but extendable.

For example:

  • Fastify makes the service very lightweight and fast. Just add routes under the /routes folder and app.register(myRoute) them in app.js or whatever.

An example route is the /healthCheck one, which also has an integration test (see below), and can be used to report service health to some monitoring solution.

  • config.js holds all app-level configuration the rest of the app could use. The whole config object can be overridden at launch/deployment time using a CONFIG environment variable.

  • Write some bloody tests, man. Ava is super simple and I have added examples for unit and integration tests.

npm run test for unit tests npm run test:int for integration tests

  • The built-in logger is doing a few convenience tasks, but is really just a thin wrapper around pino. It outputs logs in JSON, ready for ELK or other centralised monitoring.

That's it. Now go build your shit.

Todo:

  • Dockerfile and docker-compose config
  • K8s service definitions
  • Some CI config
  • Migrate from Flow to Typescript?
  • Replace Koa with Fastify
  • Add Serverless config for Lambda deployment

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •