Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ernitingarg/typescript-fastify-postgres-prisma-auth-api

Auth api using nodejs, typescript, fastify, zod, prisma, postgres, tap
https://github.com/ernitingarg/typescript-fastify-postgres-prisma-auth-api

auth-api docker docker-compose fastify github-actions jwt-authentication nodejs pino postgresql postman prisma-orm tap typescript

Last synced: about 2 months ago
JSON representation

Auth api using nodejs, typescript, fastify, zod, prisma, postgres, tap

Awesome Lists containing this project

README

        

# typescript-fastify-auth-microservice

## Prerequisites installation

### Init

```bash
npm init -y
npx tsc --init
```

### Dependencies

```
npm install fastify fastify-zod zod zod-to-json-schema @fastify/swagger @fastify/swagger-ui @fastify/jwt @prisma/client bcrypt
npm install pino pino-pretty

npm install @faker-js/faker tap ts-mock-imports
```

### Dev Dependencies

```
npm install -D ts-node ts-node-dev typescript @types/node dotenv nodemon @types/bcrypt
npm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
npm install -D @types/tap sinon
```

### Prisma Initialization

```
npx prisma init --datasource-provider postgresql
```

### Prisma db Migration

```
npx prisma migrate dev --name init
```

### Launch prisma studio

```
npx prisma studio
```

### healthcheck

- http://localhost:5000/api/health
- http://localhost:5000/api/health/db

### Swagger documentation

http://localhost:5000/docs

## Run docker locally

To run database directly inside container, please follow below steps:

- Download docker

- [Windows](https://docs.docker.com/desktop/install/windows-install/)
- [Ubuntu](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)

- To change environment variables, please use [.env](.env.example) file

- Run db docker container and app

```base
npm run start
```

- Run database docker container

```bash
npm run start:db
```

- To stop docker container

```bash
ctrl c
OR
docker-compose down

# To stop with data/volumne cleanup
docker-compose down -v --rmi all
```

- To see containers logs

```bash
docker-compose logs postgres
```

- To connect to Postgres database manually

```bash
docker exec -it postgres bash
psql -U admin -d postgresdb
```

- To see all tables in database

```bash
\dt;
```