Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/padupe/template_node-ts-prisma-postgresql

Template para desenvolvimento de API em Node.js, utilizando Typescript, Prisma ORM, PostgreSQL, Docker, Swagger e Jest.
https://github.com/padupe/template_node-ts-prisma-postgresql

docker jest nodejs postgresql prisma swagger template typescript

Last synced: 11 days ago
JSON representation

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

Awesome Lists containing this project

README

        

![img](https://github.com/padupe/template_node-ts-prisma-postgresql/blob/master/assets/template.svg)
# Template: API [Node.js](https://nodejs.org/en/ 'Node.js')
*[Typescript](https://www.typescriptlang.org/ 'Typescript') - [Prisma](https://www.prisma.io/ 'Prisma') - [PostgreSQL](https://www.postgresql.org/ 'PostgreSQL') - [Docker](https://www.docker.com/ 'Docker') - [Swagger](https://swagger.io/ 'Swagger') - [Jest](https://jestjs.io/ 'Jest')*
> Check the Documentation in pt-br by clicking 🇧🇷 [here](https://github.com/padupe/template_node-ts-prisma-postgresql/blob/master/docs/README-pt-br.md 'here').

![img](https://img.shields.io/badge/%40prisma%2Fclient-v3.11.1-blue)
![img](https://img.shields.io/badge/bcrypt-v5.0.1-blue)
![img](https://img.shields.io/badge/dotenv-v16.0.0-blue)
![img](https://img.shields.io/badge/express-v4.17.3-blue)
![img](https://img.shields.io/badge/express--async--errors-v3.1.1-blue)
![img](https://img.shields.io/badge/jsonwebtoken-v8.5.1-blue)
![img](https://img.shields.io/badge/reflect--metadata-v0.1.13-blue)
![img](https://img.shields.io/badge/swagger--ui--express-v4.3.0-blue)
![img](https://img.shields.io/badge/ts--node-v10.7.0-blue)
![img](https://img.shields.io/badge/tsyringe-v4.6.0-blue)
![img](https://img.shields.io/badge/winston-v3.7.2-blue)

## Contact the Developer





## Index
- [Contact the Developer](#contact-the-developer)
- [ERM (Entity Relationship Model)](#erm-entity-relationship-model)
- [Customer Response Flow](#customer-response-flow)
- [Project Dependencies](#project-dependencies)
- [Tools Used](#tools-used)
- [Using the Application](#using-the-application)
- [Api Documentation](#api-documentation)
- [JSON for testing via Insomnia](#json-for-testing-via-insomnia)
- [Useful Comands](#useful-commands)
- [Docker](#docker)
- [Application](#application)
- [Database](#database)
- [Automated Tests](#automated-tests)

## ERM (Entity Relationship Model)


Template-ERM

## Customer Response Flow


Template-Flow

## Project Dependencies
- [bcrypt](https://www.npmjs.com/package/bcrypt 'bcrypt'): A library to help you hash passwords;

- [dotenv](https://www.npmjs.com/package/dotenv 'dotenv'): Dotenv is a zero-dependency module that loads environment variables from a `.env` file into `process.env`;

- [express](https://expressjs.com/ '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](https://www.npmjs.com/package/express-async-errors 'express-async-errors'): A simple ES6 async/await support hack for ExpressJS;

- [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken 'jsonwebtoken'): An implementation of JSON Web Tokens;

- [reflect-metadata](https://www.npmjs.com/package/reflect-metadata '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]( '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](https://www.npmjs.com/package/tsyringe 'tsyringe'): A lightweight dependency injection container for TypeScript/JavaScript for constructor injection;

- [winston](https://www.npmjs.com/package/winston 'winston'): A log logger.

## Tools Used
- **API Documentation:** Swagger;

- **Compiler**: [SWC](https://swc.rs/ 'SWC');

- **Container:** Docker;

- **Crypto:** Bcrypt;

- **Database:** PostgreSQL;

- **Logger:** Winston;

- **ORM:** Prisma;

- **Tests:** Jest and [Supertest](https://www.npmjs.com/package/supertest 'Supertest');

- **Token:** JWT.

## Using the Application

**Requirements**:
- Node.js >= 14.x;
- Docker;
- [Yarn](https://yarnpkg.com/ 'Yarn') >= 1.22.x;
- [Insomnia](https://insomnia.rest/ 'Insomnia') (Optional).

**Step by step**
1. Clone this repository:
> SSH
```
git clone [email protected]: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
```

8. Upload the Database container
```
docker-compose -f docker/docker-compose.yaml --env-file docker/.env up -d
```

9. Run the command to instantiate Prisma
```
yarn prisma generate
```

10. Run the command to run the migrations
```
yarn migrate:run
```

11. Populate the Database
```
yarn seed
```

12. Run the Application
```
yarn dev
```

### API Documentation
[Swagger](http://localhost:3000/docs/)

*IMPORTANT:* It is necessary to run the command `yarn dev`


Swagger

### JSON for testing via Insomnia
Import this [file](https://github.com/padupe/template_node-ts-prisma-postgresql/blob/master/insomnia/Insomnia.json "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`