<<<<<<< HEAD
A real-time notification microservice for CircleConnect built with Node.js, Express, and Socket.IO.
- Real-time notifications using Socket.IO
- RESTful API endpoints for notification management
- MongoDB integration for persistent storage
- Winston logger for better debugging and monitoring
- Support for different types of notifications (posts, likes, community updates)
GET /api/notifications- Retrieve user notificationsPOST /api/notifications/send- Send a new notificationPATCH /api/notifications/:id/read- Mark a notification as read
- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
PORT=4000
MONGODB_URI=mongodb://localhost:27017/notification-service
CLIENT_URL=http://localhost:3000
NODE_ENV=development
- Start the service:
# Development mode
npm run dev
# Production mode
npm startThe service handles the following events:
connection: When a client connectsjoin: When a user joins their notification roomdisconnect: When a client disconnects
The service emits:
notification: When a new notification is created
To receive real-time notifications, connect to the Socket.IO server:
import { io } from 'socket.io-client';
const socket = io('http://localhost:4000');
// Join user's notification room
socket.emit('join', userId);
// Listen for notifications
socket.on('notification', (notification) => {
console.log('New notification:', notification);
});The service uses Winston for logging:
- Console logging in development
- File logging in production
- Error logs are stored in
error.log - Combined logs are stored in
combined.log=======
4b75998752526d4adb07f9fbbcd91dfc448f0442