Newer
Older
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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