A Node.js/Express backend server for the GoFasta GPS tracking application using MongoDB.
- Full CRUD Operations for device management
- GPS tracking data management with real-time updates
- Search and filtering capabilities for devices
- Pagination support for large datasets
- Real-time device position simulation via background services
- RESTful API with comprehensive endpoints
- PHP Integration for data retrieval and forwarding to external URLs
- Web dashboard interface for monitoring
- Input validation and security middleware
- Comprehensive logging and error handling
- Rate limiting and security headers
gofasta-server/
├── config/
│ ├── database.js # Database connection configuration
│ └── logger.js # Winston logging configuration
├── controllers/
│ └── deviceController.js # Device-related request handlers
├── middleware/
│ ├── errorHandler.js # Global error handling middleware
│ └── validation.js # Input validation middleware
├── models/
│ └── Device.js # MongoDB Device schema
├── public/
│ └── index.html # Frontend dashboard
├── routes/
│ └── deviceRoutes.js # Device API routes
├── services/
│ └── deviceService.js # Background services
├── utils/
│ └── haversine.js # Distance calculation utility
├── php-integration/ # PHP integration for data retrieval and forwarding
│ ├── gofasta-data-sender.php # Main PHP class for data operations
│ ├── config.php # PHP configuration file
│ ├── example-basic.php # Basic usage examples
│ ├── scheduled-sync.php # Automated sync script
│ ├── curl-to-php-example.php # cURL to PHP conversion example
│ ├── webhook-receiver.php # Sample webhook receiver
│ └── README.md # PHP integration documentation
├── logs/ # Application logs (auto-created)
├── .env # Environment variables
├── server.js # Main application entry point
└── package.json # Dependencies and scripts
- Clone the repository:
git clone <repository-url>
cd gofasta-server- Install dependencies:
npm install- Create environment file:
cp .env.example .env- Update the
.envfile with your MongoDB connection string and other configurations.
PORT: Server port (default: 3000)NODE_ENV: Environment mode (development/production)MONGODB_URI: MongoDB connection stringCORS_ORIGIN: Allowed CORS originsPOSITION_UPDATE_INTERVAL: Position update interval in millisecondsLOG_LEVEL: Logging level (info, debug, error)
- POST
/api/devices- Create a new device
- GET
/api/devices- Get all devices (with pagination) - GET
/api/devices/:deviceId- Get specific device - GET
/api/devices/search- Search devices with filters
- PUT
/api/devices/:deviceId- Update device information
- DELETE
/api/devices/:deviceId- Delete specific device - DELETE
/api/devices- Bulk delete multiple devices
- POST
/api/gps- Update GPS data (backward compatibility)
- GET
/health- Health check
For detailed API documentation with request/response examples, see API_DOCUMENTATION.md.
- GET device data and forward to hosted URLs
- Automated synchronization with cron jobs
- Error handling and retry logic
- Configurable endpoints and authentication
See php-integration/README.md for PHP integration documentation.
npm start: Start the production servernpm run dev: Start development server with nodemonnpm test: Run tests (placeholder)
- Start the development server:
npm run dev-
Open your browser to
http://localhost:3000to view the dashboard. -
Use the batch file for quick setup:
gofasta_start.batThe server includes a background service that automatically updates device positions every minute to simulate real-time GPS tracking.
- Helmet.js for security headers
- Rate limiting
- Input validation
- CORS configuration
- Error handling middleware
The application uses Winston for structured logging:
- Console logging for development
- File logging for production
- Different log levels (info, error, debug)
{
device_id: String (required, unique),
plate_number: String,
last_lat: Number,
last_lon: Number,
last_speed: Number,
last_update: Date,
dest_lat: Number,
dest_lon: Number
}- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
ISC