Quickly bootstrap your next TypeScript REST API project. Node 16+, auto OpenAPI, Prettier+ESLint, Jest

Overview

REST API template with autogenerated OpenAPI

Quickly bootstrap your next TypeScript REST API project with the most up to date template. Included a sample todo app with jwt based authentication.

Note: are you looking for another kind of setup/modules? Create a ticket requesting your ideal setup and I will create a dedicated branch

Features

  • Latest modules with Node 16+ and TypeScript
  • Lint and formatting via ESLint + Prettier
  • PostgreSQL as data storage (using typeorm)
  • Automatically generate OpenAPI spec/documentation (thanks to tsoa)
  • Optimized multi stage Dockerfile
  • Painless testing with Jest
  • Easy to use inversion of control with helper functions
  • JWT-based authentication sample
  • HTTP Rate limiter
  • While developing start a local PostgreSQL instance via one command bash bootstrap.sh
  • Supports watch mode
  • Git hooks to format and lint the code before committing
  • CI: GitHub action to automatically lint / build / test

Quickstart

Make sure you are running at least Node v16 and you have yarn installed, to install the modules run:

yarn install

Create your own .env file

To load configurations and secrets the project is using dotenv, a sample .env for local development is available under .env.example by renaming to .env it will be available when running the server/test

cp .env.example .env

Bootstrap the local database

Start PostgreSQL locally via docker and create the tables defined in src/entities via the following command:

bash bootstrap.sh

Add new service

Internal business logic

  1. Create new file in src/services/ e.g. product.ts
  2. Create a class with your business logic
// file: src/services/product.ts

@provideSingleton(ProductService) // auto inject
export class ProductService {

  list() {
    // sample data, this might come from the db
    return [
      {
        name: 'T-Shirt',
        quantity: 1
      }
    ];
  }
}

Add new controller

Expose an endpoint

  1. create new file in src/controllers/ e.g. product.ts
  2. Create a class with tsoa decorators and inject ProductService
// file: src/controllers/product.ts

@Route('/product') // base path for controller
@Tags('Product') // openapi section for controller endpoints
@provideSingleton(ProductController) // auto inject
export class ProductController {

  constructor(
    // load the service defined before
    @inject(ProductService) productService: ProductService,
  ) {}

  /**
   * @summary list all products
   */
  @Get('/')
  listAllProducts() {
    // get products
    const productList = this.productService.list();

    return {
      count: productList.length,
      result: productList
    };
  }
}

Start in watch mode

yarn dev

Your OpenAPI/swagger spec file generated build/swagger.json should have a new section Product with one endpoint /product/ with request and response defined based on the type returned in listAllProducts

Directory structure

  • src - source files
    • controllers - where we define external endpoints
    • services - internal business logic
    • entities - tables
    • requests - where we store the expected request data shape
    • util - helper functions
    • ioc - inversion of control helper/setup
    • database - contains helper constant Database to interact with the database
    • types - augment express typing
  • test - test files
    • intergration - tests related to the HTTP API (we call the HTTP API directly), a virtual database is used to make the testing easier and faster
    • unit - tests related to calling the functions/services directly
  • scripts - helper scripts mostly for development use only, cleanup etc.
  • build - output of tsoa build, contains the output swagger.json
  • dist - compiled source output (javascript)
You might also like...

Express.js framework boilerplate with TypeScript, Prisma, ESLint, Husky and Jest

Express.js framework boilerplate with TypeScript, Prisma, ESLint, Husky and Jest

Setup a Node.js project with Typescript, Prisma ESLint, Prettier, Husky Node.js boilerplate with Express.js, TypeScript, Prisma, ESLint, Prettier, Hus

Dec 12, 2022

vite-react-typescript with eslint and prettier predefined settings

vite-react-typescript with eslint  and prettier predefined settings

Vite + React + Typescript + Eslint + Prettier A starter for React with Typescript with the fast Vite and all static code testing with Eslint and forma

Dec 30, 2022

💅 A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, Prettier, GitHub Action releases and more.

💅 A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, Prettier, GitHub Action releases and more.

Electron App 💅  A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, P

Dec 29, 2022

TypeScript + Nextjs + Tailwind = TNT🧨 (plus Prettier and ESLint configuration).

TypeScript + Nextjs + Tailwind => TNT🧨 (plus Prettier and ESLint configuration).

Bye bye next boilerplate, welcome to TNT! About This is TNT, Nextjs boilerplate powered by Typescript, Tailwind. This template also has customized ESL

Aug 7, 2022

A Nextjs-Typescript boilerplate , configured with Tailwindcss, Eslint, Prettier, Lint-staged ,Husky and commitizen

Minimal Nextjs Typescript boilerplate A Minimal Next-Typescript boilerplate to quickly and easily bootstrap your next project. Comes pre-configured wi

Nov 4, 2022

Repository for the LogRocket meetup: Configuring ESLint And Prettier For TypeScript. ✨

logrocket-eslint-prettier-typescript ✨ Configuring ESLint And Prettier For TypeScript ✨ Join Josh Goldberg on October 21st at 2 p.m. EDT and learn how

Dec 21, 2022

🥾 A simple way to do testing AWS Services and Jest or Serverless and Jest

jest-localstack-preset Install Install via yarn or npm $ yarn add https://github.com/thadeu/jest-localstack-preset.git or $ npm i https://github.com/t

Oct 1, 2022

Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4.

Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4.

Bootstrap Tooltip Custom Class Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4. Define you

Feb 10, 2022

A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans.

A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans.

bootstrap-validate A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans. 🎉 Support us with Developer Merchandise

Jan 2, 2023
Owner
Full stack developer & DevOps
null
A template for your Node.js projects including Typescript, Eslint, Prettier, Jest and Docker.

Node.js Template Quickly start a new Node.js project A template for your Node.js projects including Typescript, Eslint, Prettier, Jest and Docker. ⏩ G

Lorenzo Carneli 2 Oct 12, 2022
A template for your NestJS projects including Typescript, Eslint, Prettier, Jest and Docker.

NestJS Template Quickly start a new NestJS project A template for your NestJS projects including Typescript, Eslint, Prettier, Jest and Docker. ⏩ Gett

Lorenzo Carneli 2 Oct 7, 2022
🚀Starter project with Angular 13, Ngx-admin, NestJS, Nx Workspace, Jest, Cypress, ESLint & Prettier 🚀

Angular 13 + Ngx-admin + NestJs + NX Starter project with Angular 13, Ngx-admin, NestJs, Nx Workspace, Jest, Cypress, ESLint & Prettier Features ✅ Ang

Wilfried 49 Jan 4, 2023
💻 A simple Create Next App template to start your projects with Next.js, TypeScript, ESLint, Prettier and other tools.

⚡ Next Typescript Template ⚡ A simple Create Next App template to start your projects with Next.js, TypeScript, ESLint, Prettier and other tools. Quic

João Gabriel 13 Nov 23, 2022
Zemi is data-driven and reverse-routing library for Express. It provides out-of-the-box OpenAPI support, allowing you to specify and autogenerate an OpenAPI spec.

zemi zemi is a data-driven routing library for Express, built with Typescript. Features: optional, out-of-the-box support for OpenAPI reverse-routing

Yoaquim Cintrón 5 Jul 23, 2022
Create a new project with Next.js, TypeScript, Eslint, Prettier in just 1 second and you don't need to setup anything.

Next + TypeScript + Eslint + Prettier Template ?? Create a new project with Next.js, TypeScript, Eslint, Prettier in just 1 second and you don't need

Hung Minh 11 Oct 2, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
REST API complete test suite using openapi.json

Openapi Test Suite Objective This package aims to solve the following two problems: Maintenance is a big problem to solve in any test suite. As the AP

PLG Works 21 Nov 3, 2022
Example auto-generated OpenAPI client library and an accompanying example Angular app.

To utilize this demo Head into petstore_frontend\petes_pets Run npm install Go to frontend_client_lib\out Run npm install Head back into petstore_fron

Alan Gross 1 Jan 21, 2022