A real-time polling application built with Node.js, Express, MongoDB, React, and Socket.io.
- ✅ Create polls with custom questions and multiple options
- ✅ Vote on polls with instant results
- ✅ Real-time updates using WebSockets
- ✅ Beautiful, responsive UI with modern design
- ✅ Live results with bar charts
- ✅ Poll management and listing
{
_id: ObjectId,
userId: ObjectId,
question: string,
options: [{ text: string, votes: number }],
createdAt: Date
}
{
_id: ObjectId,
pollId: ObjectId,
userId: ObjectId,
optionIndex: number
}
POST /api/polls
- Create a new pollGET /api/polls
- Get all pollsGET /api/polls/:id
- Get a specific pollPOST /api/polls/:id/vote
- Vote on a poll
- Node.js (v14 or higher)
- MongoDB (running locally or MongoDB Atlas)
-
Clone and install dependencies:
npm install cd client && npm install cd ..
-
Set up MongoDB:
- Make sure MongoDB is running on
mongodb://localhost:27017
- Or update the connection string in
config.js
- Make sure MongoDB is running on
-
Start the application:
# Development mode (runs both server and client) npm run dev # Or run separately: npm run server # Backend on port 5000 npm run client # Frontend on port 3000
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
polling-app/
├── server.js # Express server
├── config.js # Configuration
├── models/ # MongoDB models
│ ├── Poll.js
│ └── Vote.js
├── routes/ # API routes
│ └── polls.js
├── client/ # React frontend
│ ├── public/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── services/ # API and socket services
│ │ └── App.js
│ └── package.json
└── package.json
-
Create a Poll:
- Click "Create Poll" in the navigation
- Enter your question
- Add options (minimum 2, maximum 10)
- Click "Create Poll"
-
Vote on Polls:
- Browse polls on the home page
- Click on any poll to view details
- Select an option and click "Vote"
- See live results update in real-time
-
View Results:
- Results are displayed as both custom bars and charts
- Updates happen instantly when new votes are cast
- Total vote counts and percentages are shown
- Node.js & Express.js
- MongoDB & Mongoose
- Socket.io for real-time communication
- CORS for cross-origin requests
- React 18
- React Router for navigation
- Socket.io-client for real-time updates
- Recharts for data visualization
- Axios for API calls
- Modern CSS with responsive design
The app uses concurrent development with:
- Backend server with nodemon for auto-restart
- React development server with hot reload
- Socket.io for real-time features
-
Build the React app:
npm run build
-
Set environment variables:
MONGODB_URI=your_mongodb_connection_string PORT=5000
-
Start the production server:
npm start
MIT License