Nestjs Service Template

screenshot of Nestjs Service Template
nestjs

Nestjs Service Template

Template for new services based on NestJS with the Best Practices and Ready for Production

Overview

The author of this article has created a custom template for new services based on the NestJS framework. The template includes various features to ensure that the service is ready for production deployment, such as full dockerization, coding conventions, and performance optimizations. The author clarifies that the template does not impose any specific architecture, but rather provides a starting point for customization. The article also mentions the integration of other tools like SWC for faster compilation, Fastify as the web framework for improved performance, and husky for enforcing good quality and conventions during development. The author provides code snippets and instructions for installing and using the template.

Features

  • Fully dockerized service: The template provides a dockerized setup for both development and production environments, following best practices for performance and small image size.
  • SWC for faster compilation: The template uses SWC, which is approximately 20 times faster than the default TypeScript compiler provided by NestJS, for compiling and running tests.
  • Fastify as web framework: Instead of the default Express framework, the template integrates with Fastify, a high-performance web framework compatible with NestJS.
  • Integration with husky: Husky is integrated into the template to ensure coding conventions and quality during development. It includes running a linter, using conventional commits, and automatically running tests.
  • TypeScript type checking: The template checks for type errors using TypeScript to ensure code quality.
  • Separation of tests from production code: The template separates unit tests from production code by having a dedicated folder for unit tests.
  • Combined unit and e2e test coverage: The template allows for the combination of unit and end-to-end test coverage to provide a comprehensive view of testing.

Installation

To start using the template, follow these steps:

  1. Create a copy of the example .env file.
  2. Run the command to start the app in development mode.

The project is fully dockerized, so the necessary setup will be taken care of automatically.

Summary

The author has created a custom template for new services based on the NestJS framework. The template includes various features and optimizations to ensure that the service is ready for production deployment. It provides a fully dockerized setup, utilizes SWC for faster compilation, integrates with Fastify for improved performance, and enforces coding conventions and quality using husky. The template also includes features like TypeScript type checking, separation of tests from production code, and combined test coverage. The article provides instructions for installing and using the template.

nestjs
Nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript.

template
Templates & Themes

A template or theme refers to a pre-designed layout or structure that provides a basic framework for building a specific type of application or website. It typically includes good design, placeholder content and functional features, allowing developers to customize and fill in the details according to their specific needs.

eslint
Eslint

ESLint is a linter for JavaScript that analyzes code to detect and report on potential problems and errors, as well as enforce consistent code style and best practices, helping developers to write cleaner, more maintainable code.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.