A Node.js/Express API for managing drivers with geolocation capabilities using MongoDB.
- Create, read, update, and delete drivers
- Geospatial queries to find drivers near a specific location
- MongoDB with Mongoose ODM for data persistence
- RESTful API design
- Express middleware for error handling
- Node.js - JavaScript runtime
- Express - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- Mocha - Test framework
- Supertest - HTTP assertion library
- Nodemon - Development tool for auto-restart
-
Clone the repository
-
Install dependencies:
npm install
-
Ensure MongoDB is running on
localhost:27017
npm startThe server will run on port 3050.
npm testPOST /api/drivers
Content-Type: application/json
{
"email": "driver@example.com",
"driving": false,
"geometry": {
"type": "Point",
"coordinates": [longitude, latitude]
}
}GET /api/drivers?lng=<longitude>&lat=<latitude>Returns drivers within 200km of the specified coordinates.
PUT /api/drivers/:id
Content-Type: application/json
{
"email": "updated@example.com",
"driving": true
}DELETE /api/drivers/:iddrivers-project/
├── app.js # Express app configuration
├── index.js # Server entry point
├── package.json # Dependencies and scripts
├── controllers/
│ └── drivers_controller.js # Driver CRUD logic
├── models/
│ └── Driver.js # Driver Mongoose model
├── routes/
│ └── routes.js # API route definitions
└── test/
├── app_test.js # App tests
├── test_helper.js # Test utilities
└── controllers/
└── drivers_controller_test.js # Controller tests
email(String, required) - Driver's email addressdriving(Boolean, default: false) - Driver availability statusgeometry(GeoJSON Point) - Driver's location coordinates
NODE_ENV- Set totestwhen running tests to avoid database connection