A Node.js backend service supporting the Coding Academy E2E starter project. This service provides RESTful APIs, real-time WebSocket functionality, and MongoDB integration.
- Install dependencies:
npm install- Start the server:
npm run dev # Development mode with hot reload
npm start # Production modeGET /api/car- Get all cars with optional filteringGET /api/car/:id- Get car by IDPOST /api/car- Create new carPUT /api/car/:id- Update carDELETE /api/car/:id- Delete carPOST /api/car/:id/msg- Add message to car
POST /api/auth/signup- Register new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/user- Get all usersGET /api/user/:id- Get user by ID
GET /api/review- Get all reviewsPOST /api/review- Create new reviewDELETE /api/review/:id- Delete review
api/
├── auth/ # Authentication routes and logic
├── user/ # User management
├── car/ # Car CRUD operations
└── review/ # Review system
services/
├── db.service.js # Database connectivity
├── socket.service.js # WebSocket functionality
├── logger.service.js # Logging utility
└── util.service.js # Helper functions
middlewares/
├── requireAuth.js # Authentication middleware
└── setupAls.js # Async local storage setup
{
vendor: String,
speed: Number,
owner: { type: ObjectId, ref: 'User' },
msgs: [{
id: String,
txt: String,
by: { _id, fullname }
}]
}{
username: String,
password: String,
fullname: String,
score: Number,
isAdmin: Boolean
}{
txt: String,
byUserId: ObjectId,
aboutUserId: ObjectId
}Uses JWT (JSON Web Tokens) for stateless authentication. Tokens are stored in cookies and validated through middleware.
user-watch- User status updateschat-new-msg- New chat messagesreview-about-you- New review notificationsreview-added- Review createdreview-removed- Review deleted
try {
// Your code
} catch (err) {
logger.error('Failed to do something', err)
throw err
}Used for tracking request context, especially for logging and user sessions.
Logs are stored in the /logs directory with the following levels:
- DEBUG - Development information
- INFO - General application events
- WARN - Warning conditions
- ERROR - Error events
- Set production environment variables
- Build the frontend:
cd ../frontend-react && npm run build- Start the server:
npm startCoding Academy - Built with ❤️ for teaching modern fullstack development