/haru-api

A RESTful API built with NodeJS, Express, TypeScript. Prisma and PostgreSQL are used as database. This API is developed with Test Driven Development approach.

Primary LanguageTypeScript

Haru-Fashion API

RESTful API for Haru-Fashion e-commerce web application. Developed with NodeJS, Express, TypeScript, Prisma and PostgreSQL.

Badges

ts CircleCI Heroku Jest Prettier

Demo

🚀 API Demo
📖 API Docs

Features

Here are some of the project's features

  • CRUD Operations
  • Authentication
  • Authorization and RBAC
  • Forgot/Reset Password
  • Full-Text Search (for products)

Tech Stack

Backend: Node, Express, TypeScript
Database: Prisma + PostgreSQL
Testing: Jest
Containerization: Docker
CI/CD: CircleCI

Running Locally

Clone the project

git clone https://github.com/satnaing/haru-api.git

Go to the project directory

cd haru-api

Remove remote origin

git remote remove origin

Install dependencies

npm install

Add Environment Variables
add the following environment variables to .env file. (some env var include example values)

Click to expand!
  • NODE_ENV
  • PORT
  • POSTGRES_USER=testuser
  • POSTGRES_PASSWORD=test123
  • POSTGRES_DB=haru
  • JWT_SECRET
  • SMTP_HOST
  • SMTP_PORT
  • SMTP_USER
  • SMTP_PASS
  • FROM_NAME
  • FROM_MAIL
  • DATABASE_URL="postgresql://testuser:test123@postgres:5432/haru?schema=public"

Migrate and seed database

npx prisma migrate dev --name init
npx prisma db seed
Can't reach database server Error ?
  • Change @postgres to @localhost in DATABASE_URL inside .env for a while
DATABASE_URL="postgresql://testuser:test123@postgres:5432/test_db?schema=public"

⬇️

DATABASE_URL="postgresql://testuser:test123@localhost:5432/test_db?schema=public"

Start the server

npm run dev

Stop the server

npm run dev:down

Running Tests

To run tests, create a file called .env.test at the root of the project. Then add the following environment variables.
NODE_ENV=testing
DATABASE_URL="postgresql://prisma:prisma@localhost:5437/tests"

Note! dotenv-cli must be installed golbally before running any test

sudo npm install -g dotenv-cli

Run the test

npm run test
Can't reach database server Error ?
  • Run the test again

Stop the test

npm run test:down