1.0.0 • Published 2 years ago

express-typescript-template v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Express TS Template

Express is a highly unopinionated framework, so it can be hard to know if you are making right decisions with your tooling. This template will hopefully provide a useful starting point for your projects to hit the ground running with a good structure and workflow.

Features

  • Typescript configured with automatic dev script and testing
  • Dependency Injection via typedi package
  • API Documentation generated by apidoc
  • Express app preconfigured with several modern and useful middlewares.
    • HTTP Errors via http-error package and included error handling
    • Request logging via the morgan package
    • Several optimizations via helmet, compression packages.

Documentation

You can generate REST API Documentation using the apiDoc package. Simply run npm run docs to generate a documentation webpage. You should use the apidoc comment syntax to document your *.routes.ts files.

In package.json, there is a key called apidoc which you can use to configure the documentation output. You should modify the included key fields to match your project.

Structure

express-ts-template
src
├───config # environment variables, database connections
├───features # group related features together
│   └───feature
│       ├───index.ts # exports the things in the feature
│       ├───feature.controller.ts # controllers called in routes
│       ├───feature.model.ts # typescript object interface
│       ├───feature.repository.ts # handles database access
│       ├───feature.routes.ts # handles incoming traffic
│       ├───feature.service.ts # business logic between controller and database access
│       └───feature.test.ts # test various aspects of feature
├───middlewares # global middlewares, used by many routes
└───utils # global utilities, used in many places

Testing

Testing is done using the Jest framework.

Resources