A simple backend API for a Service Request system where users can authenticate, update their location and online status, and find nearby active service providers.
- User login with phone number and password (JWT authentication)
- Service provider location and online status update
- Fetch list of active nearby service providers based on geographic proximity
POST /api/login
Request body:
{
"phone": "09120000000",
"password": "123456"
}Response:
{
"token": "JWT_AUTH_TOKEN"
}POST /api/provider/location/update
Headers:
Authorization: Bearer <JWT_AUTH_TOKEN>Request body:
{
"lat": 35.7001,
"lng": 51.4099,
"is_online": true
}Response:
{
"msg": "Location updated",
"user": {
"phone": "09120000000",
"lat": 35.7001,
"lng": 51.4099,
"is_online": true
}
}GET /api/provider/nearby?lat=35.7021&lng=51.4031
Response example:
{
"status": "success",
"providers": [
{
"id": 12,
"name": "Ali",
"lat": 35.7010,
"lng": 51.4040
},
{
"id": 17,
"name": "Sara",
"lat": 35.7002,
"lng": 51.4050
}
]
}- Node.js
- Express.js
- MongoDB with Mongoose
- JSON Web Tokens (JWT) for authentication
- Socket.io for optional real-time communication (optional task)
- Clone the repository:
git clone <repo-url> cd <repo-folder> - Install dependencies:
npm install - Create a
.envfile based on.env.examplewith your configuration (MongoDB URI, JWT secret, etc.) - Start the server:
npm start
- Authentication middleware protects location update API; include the token in
Authorizationheader. - Location search uses a simple bounding box based on latitude and longitude deltas.
- Real-time notifications (via WebSocket) are optional and can be implemented for notifying providers about new service requests.