Skip to content

Template para desenvolvimento de API em Node.js, utilizando Typescript, Prisma ORM, PostgreSQL, Docker, Swagger e Jest.

Notifications You must be signed in to change notification settings

padupe/template_node-ts-prisma-postgresql

Repository files navigation

img

Template: API Node.js

Typescript - Prisma - PostgreSQL - Docker - Swagger - Jest

Check the Documentation in pt-br by clicking 🇧🇷 here.

img img img img img img img img img img img

Contact the Developer

Index

ERM (Entity Relationship Model)

Template-ERM

Customer Response Flow

Template-Flow

Project Dependencies

  • bcrypt: A library to help you hash passwords;
  • dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env;
  • express: Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications;
  • express-async-errors: A simple ES6 async/await support hack for ExpressJS;
  • jsonwebtoken: An implementation of JSON Web Tokens;
  • reflect-metadata: A library that serves multiple use cases (dependency composition/injection, runtime type assertions, reflection/mirroring, testing) wants the ability to add additional metadata to a class in a consistent way;
  • swagger-ui-express: This module allows you to serve auto-generated swagger-ui generated API docs from express, based on a swagger.json file. The result is living documentation for your API hosted from your API server via a route;
  • tsyringe: A lightweight dependency injection container for TypeScript/JavaScript for constructor injection;
  • winston: A log logger.

Tools Used

  • API Documentation: Swagger;
  • Compiler: SWC;
  • Container: Docker;
  • Crypto: Bcrypt;
  • Database: PostgreSQL;
  • Logger: Winston;
  • ORM: Prisma;
  • Tests: Jest and Supertest;
  • Token: JWT.

Using the Application

Requirements:

  • Node.js >= 14.x;
  • Docker;
  • Yarn >= 1.22.x;
  • Insomnia (Optional).

Step by step

  1. Clone this repository:

    SSH

    git clone git@github.com:padupe/template_node-ts-prisma-postgresql.git
    

    HTTPS

    git clone https://github.com/padupe/template_node-ts-prisma-postgresql.git
    
  2. Create the .env file in the Project root

  3. Copy the code from example.env to .env

  4. Expand the docker directory

  5. Create the .env file

  6. Copy the code from the example.env to the .env created in the docker directory

  7. Install dependencies

yarn install
  1. Upload the Database container
docker-compose -f docker/docker-compose.yaml --env-file docker/.env up -d
  1. Run the command to instantiate Prisma
yarn prisma generate
  1. Run the command to run the migrations
yarn migrate:run
  1. Populate the Database
yarn seed
  1. Run the Application
yarn dev

API Documentation

Swagger
IMPORTANT: It is necessary to run the command yarn dev

Swagger

JSON for testing via Insomnia

Import this file into Insomnia.

Useful Commands

Docker

docker-compose -f docker/docker-compose.yaml --env-file docker/.env up -d

Application

Start Application

yarn dev

Reset of Migrations and Populated Database

yarn migrate:reset

Express Start of the Application

yarn start

All necessary commands are dynamically run

Database

Visual interface for managing the Database

yarn prisma studio

Automated Tests

To run all tests

yarn test

To check test coverage

yarn test --coverage
Coverage

To run a specific test

yarn test {path_to_test+file_name_whit_extension}

Example: yarn test src/auth/jsonwebtoken.spec.ts

About

Template para desenvolvimento de API em Node.js, utilizando Typescript, Prisma ORM, PostgreSQL, Docker, Swagger e Jest.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published