Skip to content

angelkumar427/midterm_assignment_build-day

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polling App

A real-time polling application built with Node.js, Express, MongoDB, React, and Socket.io.

Features

  • ✅ 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

Data Model

Poll

{
  _id: ObjectId,
  userId: ObjectId,
  question: string,
  options: [{ text: string, votes: number }],
  createdAt: Date
}

Vote

{
  _id: ObjectId,
  pollId: ObjectId,
  userId: ObjectId,
  optionIndex: number
}

API Endpoints

  • POST /api/polls - Create a new poll
  • GET /api/polls - Get all polls
  • GET /api/polls/:id - Get a specific poll
  • POST /api/polls/:id/vote - Vote on a poll

Setup Instructions

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (running locally or MongoDB Atlas)

Installation

  1. Clone and install dependencies:

    npm install
    cd client && npm install
    cd ..
  2. Set up MongoDB:

    • Make sure MongoDB is running on mongodb://localhost:27017
    • Or update the connection string in config.js
  3. 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
  4. Access the application:

Project Structure

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

Usage

  1. Create a Poll:

    • Click "Create Poll" in the navigation
    • Enter your question
    • Add options (minimum 2, maximum 10)
    • Click "Create Poll"
  2. 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
  3. 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

Technologies Used

Backend

  • Node.js & Express.js
  • MongoDB & Mongoose
  • Socket.io for real-time communication
  • CORS for cross-origin requests

Frontend

  • 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

Development

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

Production Deployment

  1. Build the React app:

    npm run build
  2. Set environment variables:

    MONGODB_URI=your_mongodb_connection_string
    PORT=5000
  3. Start the production server:

    npm start

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published