Author • Georgi Marokov

Building a Node.js Restful API template with TypeScript, Fastify and MongoDB

  • Node.js
  • TypeScript
  • Fastify
  • MongoDB

The Reason

Have you recently started a new Node.js API project? Did you use some template or started the project from scratch? I was asking the same questions myself and I was looking for minimal boilerplate for a while. There were so many options that it was hard to pick one. Most of them are using Express.js, others are using ES5 or lack test setup. So I decided to spin one on my own and reuse it in the future. Here is the repo at GitHub.

The Project

Short description of what you can find in this project:

API Layer

  • Node.js version 10 or higher.
  • TypeScript, the obvious choice for enhanced type safety.
  • Fastify for its asynchronous nature and being faster than Express or Restify
  • Nodemon in the development environment, ensuring seamless updates and server restarts.

Data Management

  • MongoDB, managed efficiently with Mongoose.
  • Docker, providing a robust container for the MongoDB service.

Testing Suite

  • Jest, the go-to testing framework for Node.js.
  • An in-memory Mongod server for effortless database mocking.
  • Coverall, a handy tool for collecting coverage data following Jest's report generation.

Code Quality and Analysis

  • ESLint configuration.
  • Prettier configuration integrated with the linter.
  • Editor configuration for consistent code styling.


  • Swagger UI for clear and interactive API documentation.
  • Postman collections derived from endpoint testing, offering a practical resource for API consumers.

Continuous Integration (CI)

Incorporating continuous integration into the workflow with Travis CI, the process unfolds like this:

  1. Dependency installation.
  2. Test execution.
  3. Coverage data collection, promptly pushed to Coverall.


With this template, you're well-equipped to forge your Node.js RESTful API project with TypeScript, Fastify, and MongoDB. Whether you're starting afresh or seeking to streamline an existing endeavor, the tools and practices outlined here promise efficiency, clarity, and maintainability. local