This project provides the backend API for an event registration system, built with Node.js, Express.js, and PostgreSQL.
- User registration and authentication (JWT)
- Event creation, viewing, updating, and deletion (admin only)
- User registration for events
- Viewing and canceling user registrations
Before you begin, ensure you have the following installed:
- Node.js (LTS version recommended)
- pnpm
- PostgreSQL Database (e.g., a Neon.tech instance)
- An API client like Postman or Insomnia for testing the API.
-
Clone the repository:
git clone https://github.com/DevYon4s/Event-registration-system.git cd Event-registration-system -
Install dependencies:
pnpm install
Create a .env file in the root of your project and add the following environment variables:
DATABASE_URL=your_postgresql_connection_string
JWT_SECRET=your_jwt_secret
PORT=5000
- Replace
your_postgresql_connection_stringwith the connection string to your PostgreSQL database (e.g., from Neon.tech). - Replace
your_jwt_secretwith a strong, random string. This will be used for signing JWTs. PORTis optional; defaults to5000if not specified.
-
Start the server:
npm start
The server will start on the port specified in your
.envfile (default: 5000).
Use your API client (Postman, Insomnia, etc.) to test the following endpoints. Replace http://localhost:5000 with your server's actual address and port if different.
- Method:
POST - URL:
/api/users - Headers:
Content-Type:application/json
- Body (raw, JSON):
{ "username": "testuser", "email": "test@example.com", "password": "password123" } - Expected Response:
201 Createdwith the new user object.
- Method:
POST - URL:
/api/users/login - Headers:
Content-Type:application/json
- Body (raw, JSON):
{ "email": "test@example.com", "password": "password123" } - Expected Response:
200 OKwith atokenin the response body. Save this token for authenticated requests.
- Method:
GET - URL:
/api/events - Expected Response:
200 OKwith an array of event objects.
- Method:
POST - URL:
/api/events - Headers:
Content-Type:application/jsonAuthorization:Bearer <YOUR_JWT_TOKEN>(Use the token from an admin user.)
- Body (raw, JSON):
{ "title": "Tech Conference 2025", "description": "A conference on the latest in technology.", "date": "2025-10-26T09:00:00Z", "location": "Convention Center" } - Expected Response:
201 Createdwith the new event object.
- Method:
GET - URL:
/api/events/:id(Replace:idwith an actual event ID.) - Expected Response:
200 OKwith the specific event object.
- Method:
PUT - URL:
/api/events/:id - Headers:
Content-Type:application/jsonAuthorization:Bearer <YOUR_JWT_TOKEN>
- Body (raw, JSON):
{ "title": "Updated Tech Conference 2025", "description": "An updated description for the conference.", "date": "2025-10-27T10:00:00Z", "location": "New Convention Hall" } - Expected Response:
200 OKwith the updated event object.
- Method:
DELETE - URL:
/api/events/:id - Headers:
Authorization:Bearer <YOUR_JWT_TOKEN>
- Expected Response:
204 No Content.
- Method:
POST - URL:
/api/registrations - Headers:
Content-Type:application/jsonAuthorization:Bearer <YOUR_JWT_TOKEN>(Use the token of the user who is registering.)
- Body (raw, JSON):
{ "userId": <USER_ID>, // The ID of the user from your database "eventId": <EVENT_ID> // The ID of the event you want to register for } - Expected Response:
201 Createdwith the new registration object.
- Method:
GET - URL:
/api/registrations/user/:userId(Replace:userIdwith the ID of the user whose registrations you want to view.) - Headers:
Authorization:Bearer <YOUR_JWT_TOKEN>
- Expected Response:
200 OKwith an array of registration objects for that user.
- Method:
DELETE - URL:
/api/registrations/:id(Replace:idwith the ID of the registration to cancel.) - Headers:
Authorization:Bearer <YOUR_JWT_TOKEN>
- Expected Response:
204 No Content.