Robust Node.js backend for BusGo bus booking application featuring Google OAuth, ticketing logic, secure JWT authentication, and AdminJS dashboard for data management.
- π Google OAuth 2.0 - Secure authentication with JWT tokens
- ποΈ Ticketing System - Complete booking and ticket management
- ποΈ MongoDB Integration - Mongoose ODM with optimized queries
- π§βπΌ AdminJS Dashboard - Admin panel for data management
- β‘ Performance - Optimized queries with proper indexing
- π Token Management - Access & refresh token handling
- π CORS Enabled - Cross-origin resource sharing
- π‘οΈ Type Safety - Full TypeScript implementation
- π― Error Handling - Standardized API responses
Production URL: https://busgo-node-js.onrender.com
https://busgo-node-js.onrender.com/api/v1
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/user/login |
Google OAuth authentication | β |
POST |
/user/refresh-token |
Refresh access token | β |
GET |
/city |
Get all cities | β |
GET |
/bus?busId={busExternalId} |
Get bus details by ID | β |
GET |
/bus/search?from={from}&to={to}&date={date}&tags={tags}&sortBy={sortBy} |
Search buses | β |
GET |
/ticket |
Get user tickets | β |
POST |
/ticket |
Book new ticket | β |
POST |
/seed |
Seed database | β |
https://busgo-node-js.onrender.com/admin
- Node.js 18+ - JavaScript runtime
- Express 5.1.0 - Web framework
- TypeScript 4.9.5 - Type safety
- MongoDB - Database with Mongoose ODM
- Google Auth Library 10.1.0 - OAuth 2.0 integration
- JSON Web Token 9.0.2 - JWT authentication
- Express Session 1.18.1 - Session management
- CORS 2.8.5 - Cross-origin requests
- AdminJS 6.8.7 - Admin dashboard
- Colors 1.4.0 - Console logging
- Nanoid 5.1.5 - ID generation
- UUID 11.1.0 - Unique identifiers
- Node.js 18+
- MongoDB instance
- Google OAuth credentials
-
Clone repository
git clone https://github.com/chayan-1906/BusGo-Node.js.git cd BusGo-Node.js -
Install dependencies
npm install
-
Environment setup
cp .env.example .env
-
Configure environment
PORT=4000 MONGO_URI=mongodb://localhost:27017/busgo WEB_GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret ACCESS_TOKEN_SECRET=your_access_token_secret ACCESS_TOKEN_EXPIRY=1d REFRESH_TOKEN_SECRET=your_refresh_token_secret REFRESH_TOKEN_EXPIRY=30d COOKIE_PASSWORD=your_cookie_password SEED_SECRET=your_seed_secret ADMIN_LOGIN_EMAIL=admin@busgo.com ADMIN_LOGIN_PASSWORD=your_admin_password
-
Seed database
npm run seed:data
-
Start development server
npm run dev
src/
βββ config/ # Database & app configuration
βββ controllers/ # Request handlers
βββ middleware/ # Authentication middleware
βββ models/ # Mongoose schemas
βββ routes/ # API route definitions
βββ types/ # TypeScript type definitions
βββ utils/ # Utility functions
βββ seedData.ts # Database seeding data
βββ seedScript.ts # Seeding script
βββ server.ts # Application entry point
{
userExternalId: string // UUID
googleId: string // Google OAuth ID
email: string // User email
name: string // Display name
profilePicture: string // Avatar URL
}{
busExternalId: string // UUID
from: string // Origin city
to: string // Destination city
departureTime: Date // Departure time
arrivalTime: Date // Arrival time
duration: number // Trip duration (minutes)
availableSeats: number // Available seats
price: number // Ticket price
originalPrice: number // Original price
company: string // Bus operator
busTags: string[] // Bus amenities
rating: number // User rating
totalReviews: number // Review count
badges: string[] // Quality badges
seats: ISeat[][] // Seat layout
}{
ticketExternalId: string // UUID
userId: ObjectId // User reference
userExternalId: string // User UUID
busId: ObjectId // Bus reference
busExternalId: string // Bus UUID
date: Date // Travel date
seatNumbers: number[] // Selected seats
totalFare: number // Total amount
status: enum // Upcoming/Completed/Cancelled
bookedAt: Date // Booking timestamp
pnr: string // PNR number
}curl -X POST https://busgo-node-js.onrender.com/api/v1/user/login \
-H "Content-Type: application/json" \
-d '{"idToken": "google_id_token"}'curl "https://busgo-node-js.onrender.com/api/v1/bus/search?from=Mumbai&to=Pune&date=2025-07-15&tags=A/C,Luxury&sortBy=price"curl "https://busgo-node-js.onrender.com/api/v1/bus?busId=BUS_12345"curl -X POST https://busgo-node-js.onrender.com/api/v1/ticket \
-H "Authorization: Bearer your_access_token" \
-H "Content-Type: application/json" \
-d '{"busExternalId": "BUS_12345", "seatNumbers": [1,2], "date": "2025-07-15"}'- Google OAuth Login - Frontend sends Google ID token
- Token Verification - Backend verifies with Google
- User Creation - New users auto-created
- JWT Generation - Access & refresh tokens issued
- Protected Routes - Bearer token required
Access AdminJS dashboard for data management:
- URL:
https://busgo-node-js.onrender.com/admin - Features: CRUD operations, user management, analytics
- Authentication: Admin credentials required
- Database Indexing - Optimized queries
- Connection Pooling - MongoDB connection optimization
- Error Handling - Standardized responses
- Logging - Colored console output
# Development server
npm run dev
# Seed database
npm run seed:data
# Build production
npm run build- Connect GitHub repository
- Set environment variables
- Deploy automatically on push
# API Testing with curl
curl -X GET https://busgo-node-js.onrender.com/api/v1/city
# Health Check
curl https://busgo-node-js.onrender.com/admin- Node.js: β₯18.0.0
- MongoDB: β₯5.0
- Memory: 512MB RAM minimum
- Storage: 1GB disk space
- Fork repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push branch (
git push origin feature/amazing-feature) - Open Pull Request
- Cold starts on the Render free tier may cause delays
Padmanabha Das
- GitHub: @chayan-1906
- LinkedIn: Padmanabha Das
- Email: padmanabhadas9647@gmail.com
Give a βοΈ if this project helped you!
- Mobile App: BusGo React Native
Made with β€οΈ by Padmanabha Das
β Star this repo if you found it helpful!
