Skip to content

Latest commit

 

History

History
126 lines (83 loc) · 3.33 KB

README.md

File metadata and controls

126 lines (83 loc) · 3.33 KB

Express.js, Prisma, and PostgreSQL Demo

This is a personal practice project for experimenting with Prisma, Express.js, and PostgreSQL.

Table of content

Getting Started

Clone the repository

  git clone <repository-url>
  cd expressjs-prisma-postgres-demo

↑ Top

Install dependencies

  npm install

↑ Top

Set up your PostgreSQL database

  • Open psql shell and connect postgres database on your local machine
psql -h localhost -p 5432 -U postgres postgres
  • Create database using psql
CREATE DATABASE your-db-name;
  • Create a new user with a password on you postgresql server and give it rule as superuser
CREATE USER your-db-user WITH PASSWORD your-password SUPERUSER;
  • Exit the psql shell
\q

↑ Top

Update the database credentials

  • In src/config/.env, provide the necessary database credentials:

    DATABASE_URL=postgresql://<username>:<password>@localhost:5432/<DB>
    DATABASE_DEV=db_name
    DATABASE_PROD=db_name
    DATABASE_TEST=db_name
    DATABASE_USERNAME=user_name
    DATABASE_PASSWORD=password
  • In `prisma/.env``, make sure the database URL matches your PostgreSQL database configuration:

    # db_url like that 'postgresql://mo:test123@localhost:5432/prisma_demo'
    DATABASE_URL=db_url
    DATABASE_URL_TEST=db_url

↑ Top

Migrate and seed the database

  npx prisma migrate dev

↑ Top

Start the Server

  • Development Mode: Run npm run start:dev to start the server with nodemon for automatic reloading during development.
  • Production Mode: Run npm run start:prod to start the server in production mode.

↑ Top

Testing

  • Run tests using Jest:
    • npm test: Run tests in the testing environment.
    • npm run test:coverage: Run tests with code coverage report.

↑ Top

Usage

  • Use your preferred API client (e.g., Postman, curl) to interact with the API.
  • Alternatively, you can use the REST Client extension in Visual Studio Code to test the API directly from the provided rest.http file. The rest.http file contains URLs to all endpoints, making it convenient to make requests and test your API.

The npm test command will not only start the server but also run Jest for testing purposes.

↑ Top

Enjoy the demo!