Skip to content

Backend Template in NodeJS with Fastify micro framework in Typescript

License

Notifications You must be signed in to change notification settings

Artursrossi/template-backend-nodejs

Repository files navigation

TEMPLATE-BACKEND-NODEJS

❯ Template developed by Artur Schincariol Rossi


Table of Contents

Overview

❯ Base backend template for building application with the Fastify framework.

Features

  • Code formatters && Linters (Eslint + Prettier)
  • API Documentation (w/ Swagger)
  • Database on container (Docker)
  • Rate Limit
  • Security Headers
  • Authentication System w/ Bcrypt and JWT Token (using HTTP Only Cookies)
  • Unit Tests w/ Vitest

TODO List

  • Task 1: Implement a password recovery system using nodemailer for sending emails

Project Structure

└── template-backend-nodejs/
    ├── LICENSE
    ├── README.md
    ├── docker-compose.yml
    ├── misc
    │   └── Insomnia.json
    ├── package-lock.json
    ├── package.json
    ├── prisma
    │   ├── migrations
    │   ├── schema.prisma
    │   └── seed.ts
    ├── src
    │   ├── @types
    │   ├── config
    │   ├── controllers
    │   ├── error-handler.ts
    │   ├── libs
    │   ├── middlewares
    │   ├── mocks
    │   ├── schemas
    │   └── server.ts
    ├── tsconfig.json
    └── vitest.config.ts

Technologies

  • NodeJS
  • Fastify
  • Typescript
  • PostgreSQL
  • Docker
  • Prisma ORM
  • Bcrypt
  • JsonWebToken
  • Swagger
  • Zod
  • Prettier && Eslint

Getting Started

Prerequisites

Before getting started with template-backend-nodejs, ensure your runtime environment meets the following requirements:

  • Version Control System: Git
  • Javascript Runtime: NodeJS
  • Package Manager: Npm (Installed with NodeJS)
  • Container Runtime: Docker

Installation

  1. Clone the template-backend-nodejs repository:
❯ git clone https://github.com/Artursrossi/template-backend-nodejs
  1. Navigate to the project directory:
cd template-backend-nodejs
  1. Install the project dependencies: Using npm  
❯ npm install
  1. Start the container containing the database: Using docker  
❯ docker-compose up -d

Configuration

Set the environment variables by creating a .env file using .env.example

Generate a random string for the JWT_SECRET variable by the following command: Using nodejs  

❯  node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Configure Database Schema:

  1. Generate prisma client: Using npm  
❯ npx prisma generate
  1. Apply prisma schema on Database: Using npm  
❯ npx prisma db push
  1. Populate data to Database: Using npm  
❯ npm run seed

Usage

Run template-backend-nodejs using one of the following methods:

Development environment:

  1. Start project without generating a build: Using npm  
❯ npm run dev

Production environment:

  1. Generate a optimized build version: Using npm  
❯ npm run build
  1. Start project using the optimized build version: Using npm  
❯ npm run start

Testing

Run the test suite using the following command: Using npm  

❯ npm test

About

Backend Template in NodeJS with Fastify micro framework in Typescript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published