HaroonAwan / books-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Books NodeJS Express API with PostgreSQL

This project provides a simple RESTful API for managing books using NodeJS, Express, and PostgreSQL.

Prerequisites

Make sure you have the following installed on your machine:

Getting Started

Environment Variables

The following environment variables are required to set up and run the application: Create an .env file

PORT=3000

POSTGRES_USER=admin
POSTGRES_PASSWORD=7gvl3A0
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=books

POSTGRES_HOST_LOCAL=localhost
  1. Installation: Install all the dependencies:

    npm install
  2. Docker: Run the PostgreSQL database using Docker Compose:

    docker-compose up
  3. Database Migrations: Apply database migrations:

    npm run migration:up
  4. Testing: Run the test suite:

    npm run test

Other commands

  1. To stop the containers and remove them:

    docker-compose down
  2. Rollback the last batch of migrations:

    npm run migration:down
  3. Building: Compile the TypeScript code:

    npm run build
  4. Running the API: Start the Express server:

    npm run start

API Endpoints

The main endpoint for managing books is /books. You can use methods like GET, POST, PUT, and DELETE to interact with the database.

Note: Always ensure the PostgreSQL and API container is up and running before running migrations.

About


Languages

Language:TypeScript 89.9%Language:JavaScript 6.9%Language:Dockerfile 3.2%