Skip to content
README.md 2.52 KiB
Newer Older
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

# Express Backend with PostgreSQL Database Integration

This project is an Express.js backend application integrated with a PostgreSQL database. It provides endpoints for user registration, login, and account management.

## Setup

1. Install dependencies:
   ```bash
   npm install express bcrypt pg cors
   ```

2. Set up a PostgreSQL database with the following credentials:
   - Username: ``
   - Password: ``
   - Host: ``
   - Port: ``
   - Database: `Express`

3. Run the application:
   ```bash
   node app.js
   ```

## Endpoints

### Registration

- **Endpoint:** POST `/register`
- **Description:** Registers a new user.
- **Request Body:**
  ```json
  {
    "full_names": "John Doe",
    "email": "john@example.com",
    "address": "123 Street, City",
    "password": "password123"
  }
  ```
- **Response:**
  - `201`: User registered successfully. Returns the user ID.
  - `409`: Email already exists.
  - `500`: Server error.

### Login

- **Endpoint:** POST `/login`
- **Description:** Authenticates a user.
- **Request Body:**
  ```json
  {
    "email": "john@example.com",
    "password": "password123"
  }
  ```
- **Response:**
  - `200`: Login successful. Returns the user ID.
  - `400`: User not found.
  - `401`: Invalid credentials.
  - `500`: Server error.

### Account

#### Create Account Details

- **Endpoint:** POST `/account`
- **Description:** Creates account details for a user.
- **Request Body:**
  ```json
  {
    "user_id": 1,
    "details": "Account details..."
  }
  ```
- **Response:**
  - `201`: Account details created successfully. Returns the created details.
  - `500`: Server error.

#### Get Account Details

- **Endpoint:** GET `/account/:userId`
- **Description:** Retrieves account details for a user.
- **Response:**
  - `200`: Account details found. Returns the details.
  - `204`: No details found.
  - `500`: Server error.

#### Update Account Details

- **Endpoint:** PUT `/account/:userId`
- **Description:** Updates account details for a user.
- **Request Body:**
  ```json
  {
    "details": "Updated account details..."
  }
  ```
- **Response:**
  - `200`: Account details updated successfully. Returns the updated details.
  - `404`: Details not found.
  - `500`: Server error.

#### Get User IDs

- **Endpoint:** GET `/userIds`
- **Description:** Retrieves all user IDs.
- **Response:**
  - `200`: User IDs retrieved successfully. Returns an array of user IDs.
  - `500`: Server error.

## Technologies Used

- Node.js
- Express.js
- PostgreSQL
- Bcrypt for password hashing
- CORS for cross-origin resource sharing