An open API service indexing awesome lists of open source software.

https://github.com/shubhamch95/activity-booking-backend

This is a backend API for an activity booking application built with Node.js, Express, and MongoDB. It allows users to register, log in, view available activities, book activities, and view their bookings. The API uses JWT for authentication and bcrypt for password hashing.
https://github.com/shubhamch95/activity-booking-backend

bcryptjs express-validator expressjs javascript mongodb nodejs

Last synced: about 1 month ago
JSON representation

This is a backend API for an activity booking application built with Node.js, Express, and MongoDB. It allows users to register, log in, view available activities, book activities, and view their bookings. The API uses JWT for authentication and bcrypt for password hashing.

Awesome Lists containing this project

README

          

# ๐Ÿƒโ€โ™‚๏ธ Activity Booking API

A simple backend API for user registration, login, listing activities, and booking them โ€” built with **Node.js**, **Express**, and **MongoDB**.

---

## ๐Ÿ“ฆ Tech Stack

- **Node.js**
- **Express.js**
- **MongoDB** with Mongoose
- **JWT Authentication**
- **bcrypt** for password hashing
- **express-validator** for input validation

---

## โš™๏ธ Setup Instructions

### 1. Clone the Repository

```bash
git clone https://github.com/your-username/activity-booking-api.git
cd activity-booking-api
```

### 2. Install Dependencies

```bash
npm install
```

### 3. Configure Environment Variables

Create a `.env` file in the root directory with the following content:

```env
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_super_secret_key
```

### 4. Start the Server

```bash
npm run dev
```

Server will be running at:
๐Ÿ“ `http://localhost:5000`

---

## ๐Ÿงช API Endpoints

### โœ… Auth

#### `POST /api/auth/register`
Register a user
**Body:**
```json
{
"name": "John Doe",
"email": "john@example.com",
"phone": "1234567890",
"password": "your_password"
}
```

#### `POST /api/auth/login`
Login and get a token
**Body:**
```json
{
"email": "john@example.com",
"password": "your_password"
}
```

---

### ๐Ÿ“… Activities

#### `GET /api/activity/getActivities`
Get a list of all public activities

#### `POST /api/activity/createActivity`
Create a new activity (authorized users only)
**Headers:**
`Authorization: Bearer `
**Body:**
```json
{
"title": "Yoga Session",
"description": "A relaxing yoga class",
"location": "Community Center",
"date": "2025-06-01",
"time": "10:00 AM"
}
```

---

### ๐Ÿ“– Bookings

#### `POST /api/booking/book/:activityId`
Book an activity
**Headers:**
`Authorization: Bearer `

#### `GET /api/booking/myBookings`
List the user's booked activities
**Headers:**
`Authorization: Bearer `

---

## โœ… Bonus Features

- ๐Ÿ” Passwords securely hashed with **bcrypt**
- ๐Ÿ›ก JWT token-based authentication
- ๐Ÿ“ฅ Input validation via **express-validator**
- ๐Ÿงน Clean, modular code structure

---

## ๐Ÿ“ Folder Structure

```
๐Ÿ“ฆ project-root
โ”œโ”€โ”€ controllers/
โ”œโ”€โ”€ models/
โ”œโ”€โ”€ routes/
โ”œโ”€โ”€ middleware/
โ”œโ”€โ”€ validators/
โ”œโ”€โ”€ config/
โ”œโ”€โ”€ server.js
โ”œโ”€โ”€ .env
โ””โ”€โ”€ README.md
```
## Contributing
๐Ÿš€ Contributions are welcome! Follow these steps:
1. **Fork the repository.**
2. **Create a new feature branch.**
3. **Commit your changes.**
4. **Push to your branch and submit a Pull Request (PR).**

## License
๐Ÿ“œ **MIT License** - Free to use and modify!

---
Made with โค๏ธ