Simple Express.js backend server for the BandwidthShare mobile app.
cd backend
npm installDevelopment (with auto-reload):
npm run devProduction:
npm start- URL:
http://localhost:3000 - API Base:
http://localhost:3000/api
POST /api/auth/signup- Create new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout user
GET /api/earnings- Get user earningsPUT /api/earnings- Update earnings (admin/testing)
GET /api/statistics?period=daily|weekly|monthly- Get bandwidth statistics
GET /api/settings- Get user settingsPUT /api/settings- Update settings
POST /api/bandwidth/start- Start bandwidth sharingPOST /api/bandwidth/stop- Stop bandwidth sharingGET /api/bandwidth/data-shared- Get data shared todayPOST /api/bandwidth/update-data- Update data shared (called by client)
All protected routes require a JWT token in the Authorization header:
Authorization: Bearer <token>
POST /api/auth/signup
{
"email": "user@example.com",
"password": "password123",
"name": "John Doe"
}
Response:
{
"success": true,
"data": {
"user": { "email": "user@example.com", "name": "John Doe" },
"token": "jwt-token-here"
}
}POST /api/auth/login
{
"email": "user@example.com",
"password": "password123"
}
Response:
{
"success": true,
"data": {
"user": { "email": "user@example.com", "name": "John Doe" },
"token": "jwt-token-here"
}
}GET /api/earnings
Headers: Authorization: Bearer <token>
Response:
{
"success": true,
"data": {
"today": 0.45,
"total": 12.34
}
}Currently uses in-memory storage (data is lost on server restart).
-
MongoDB:
npm install mongoose
-
PostgreSQL:
npm install pg
-
SQLite:
npm install sqlite3
Create a .env file:
PORT=3000
JWT_SECRET=your-super-secret-key-change-this-in-productionTest endpoints with:
- Postman
- curl
- Thunder Client (VS Code extension)
Example curl command:
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'- ✅ Basic server setup (done)
- ⏳ Connect to database
- ⏳ Add input validation
- ⏳ Add rate limiting
- ⏳ Add logging
- ⏳ Add error handling middleware
- ⏳ Add API documentation (Swagger)
- JWT_SECRET: Change the default secret in production!
- Password Hashing: Uses bcryptjs (10 rounds)
- CORS: Enabled for all origins (restrict in production)
- Data Persistence: Currently in-memory (add database)
express- Web frameworkcors- CORS middlewarejsonwebtoken- JWT authenticationbcryptjs- Password hashingbody-parser- Request body parsing