/node-ts-boilerplate

A Nodejs RestAPI boilerplate using: Typescript, MongoDB, Redis, SocketIO

Primary LanguageTypeScriptMIT LicenseMIT

Node API boilerplate

1. Ecosystem

2. Quick start

2.1. Project structure

  • Separate Express 'app' and 'server': allowing a flexible testing environement of the API using Chai HTTP
  • Solution structured by self-contained components (features): each feature (For example auth or rooms) contains it's own logic:
    - Routes
    - Controllers
    - Services
    - Validations
    - Models
    - Unit tests

2.1. Error Handling

  • Errors handled centrally, not within a middlewares: see src/middlewares/error.ts.
  • Operational and programmer errors are seperated: we use a custom error class for this to extend the built in Error class (see src/utils/ApiError.ts)
  • Error logging using Winston: see src/utils/logger.ts

2.2. Code Style Practices

  • Eslint + Prettier + VsCode configuration to enforce code styles on file save
  • Husky + lint-staged to enforce code styles before commits

2.3. Testing

2.4. Socket

  • Multinode support using redis socketio adapter
  • Socket handlers separated per topic
  • Socket authentification middleware

2.5. Docker

2.6. TravisCI

Really simple CI/CD pipeline that gets triggered on every commit. CI/CD pipeline

3. Prospects

  • Integrate test coverage into the CI/CD pipeline