Backend REST API for managing parking events. Implemented with Node.js, Express and MongoDB. The service provides endpoints to load data from a CSV file and to retrieve parking events.
- Node.js
- Express
- MongoDB (Mongoose)
- csv-parser
- Retrieve all parking events.
- Retrieve a single parking event by
event_id. - Bulk load events from CSV (
/data/events.csv) into the database. - Clean project structure with routes and models separation.
- Error handling with appropriate HTTP status codes.
project-root/
├── models/
│ └── ParkingEvent.js # Mongoose model for parking events
├── routes/
│ └── parking.routes.js # API routes: GET all, GET by id, POST load CSV
├── data/
│ └── events.csv # Example dataset (CSV)
├── server.js # Application entry point
├── package.json
├── .env # Environment variables (not committed)
└── README.md
- Clone the repository:
git clone <your-repo-url>
cd <repo-directory>- Install dependencies:
npm install- Create a
.envfile with the following variables:
MONGODB_URI=mongodb://localhost:27017/smartpark
PORT=3000
- Start the application in development:
npm run devOr in production:
npm startIf
npm run devis not defined, installnodemonand run:
npm install --save-dev nodemon
npx nodemon server.jsImplemented endpoints:
-
GET /api/events
Retrieve all parking events. Returns a JSON array ordered byevent_id. -
GET /api/events/:id
Retrieve a single event byevent_id. Returns 404 if not found. -
POST /api/events/load
Load events fromdata/events.csvand insert them into the database. Returns a summary with the inserted count.
Planned or optional endpoints (not necessarily implemented in current code):
POST /api/events— Create a single parking eventPUT /api/events/:id— Update an event byevent_idDELETE /api/events/:id— Delete an event byevent_id
Get all events:
curl http://localhost:3000/api/eventsGet event by id:
curl http://localhost:3000/api/events/1Load CSV into database:
curl -X POST http://localhost:3000/api/events/load500 Internal Server Errorfor unexpected failures.404 Not Foundwhen a requestedevent_idcannot be found.
Use tools such as Postman, HTTPie or cURL to test endpoints. For local development, ensure MongoDB is running and MONGODB_URI is set correctly.
MIT License.