Skip to content

ernitingarg/typescript-fastify-postgres-prisma-auth-api

Repository files navigation

typescript-fastify-auth-microservice

Prerequisites installation

Init

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

Swagger documentation

http://localhost:5000/docs

Run docker locally

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

  • Download docker

  • To change environment variables, please use .env file

  • Run db docker container and app

npm run start
  • Run database docker container
npm run start:db
  • To stop docker container
ctrl c
OR
docker-compose down

# To stop with data/volumne cleanup
docker-compose down -v --rmi all
  • To see containers logs
docker-compose logs postgres
  • To connect to Postgres database manually
 docker exec -it postgres bash
 psql -U admin -d postgresdb
  • To see all tables in database
\dt;