<<<<<<< HEAD
A secure and scalable online voting system with role-based access.
- Admin & User login
- Secure voting
- Result calculation
- Role-based access
- Frontend: React
- Backend: Node.js, Express
- Database: MongoDB
- Clone repo
- Install dependencies
- Run frontend & backend
A full-stack web application for creating polls, voting, and viewing real-time results. Built with React and Node.js/Express, featuring MongoDB for data persistence.
- Create Polls: Easily create polls with custom questions and multiple options
- Vote: Cast votes on any poll with real-time vote counting
- Real-time Updates: Automatic refresh of poll results every 3 seconds
- Anonymous Voting: Support for both anonymous and non-anonymous voting modes
- Poll Management: View all polls, see detailed results, and delete polls
- Responsive Design: Clean and modern UI built with React
- React 19.2.3 - UI library
- React Scripts 5.0.1 - Build tooling
- CSS - Styling
- Node.js - Runtime environment
- Express 4.19.0 - Web framework
- MongoDB with Mongoose 8.0.0 - Database and ODM
- CORS 2.8.5 - Cross-origin resource sharing
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- npm (v6 or higher) or yarn
- MongoDB (local installation or MongoDB Atlas account)
-
Clone the repository
git clone <https://github.com/srijan43/CrowdVoice> cd LPU
-
Install backend dependencies
cd backend npm install -
Install frontend dependencies
cd client npm install cd ../..
Create a .env file in the backend directory (optional for local development):
PORT=5000
MONGODB_URI=mongodb://127.0.0.1:27017/polling_appFor production or MongoDB Atlas, set:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/polling_appNote: If MONGODB_URI is not set, the application defaults to mongodb://127.0.0.1:27017/polling_app.
-
Start MongoDB (if using local MongoDB)
# On Windows mongod # On macOS/Linux sudo systemctl start mongod # or mongod
-
Start the backend server
cd backend npm startThe backend will run on
http://localhost:5000 -
Start the frontend (in a new terminal)
cd backend/client npm startThe frontend will open at
http://localhost:3000
-
Build the frontend
cd backend/client npm run build -
Start the backend (serves the built frontend)
cd backend npm start
LPU/
βββ backend/
β βββ client/ # React frontend application
β β βββ public/ # Static files
β β βββ src/ # React source code
β β βββ build/ # Production build (generated)
β β βββ package.json # Frontend dependencies
β β βββ vercel.json # Vercel deployment config
β βββ server.js # Express backend server
β βββ package.json # Backend dependencies
β βββ Procfile # Heroku/Railway deployment config
βββ frontend/ # Alternative frontend (if used)
βββ deploy.sh # Deployment script
βββ README.md # This file
http://localhost:5000/api
GET /api/pollsResponse: Array of all polls
GET /api/polls/:idResponse: Poll object with question, options, and vote counts
POST /api/polls
Content-Type: application/json
{
"question": "What is your favorite programming language?",
"options": ["JavaScript", "Python", "Java", "C++"],
"allowAnonymous": true
}Response: Created poll object
POST /api/polls/:id/vote
Content-Type: application/json
{
"optionIndex": 0,
"userName": "John" // Optional if allowAnonymous is true
}Response: Updated poll object with new vote counts
POST /api/polls/:id/clear-vote
Content-Type: application/json
{
"optionIndex": 0,
"userName": "John" // Optional if allowAnonymous is true
}Response: Updated poll object with decremented vote count
DELETE /api/polls/:idResponse: Success message
chmod +x deploy.sh
./deploy.sh-
Railway/Render
- Connect your GitHub repository
- Set environment variable:
MONGODB_URI - Set build command:
npm install - Set start command:
npm start
-
Heroku
heroku create your-app-name heroku config:set MONGODB_URI=your_mongodb_uri git push heroku main
-
Vercel
- Connect your GitHub repository
- Set root directory to
backend/client - Vercel will auto-detect React and deploy
-
Netlify
- Connect your GitHub repository
- Set build command:
cd backend/client && npm install && npm run build - Set publish directory:
backend/client/build
Make sure to set:
MONGODB_URI- Your MongoDB connection stringPORT- Server port (usually auto-set by hosting platform)
Run frontend tests:
cd backend/client
npm testContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
Your Name / Your Organization
- React team for the amazing framework
- Express.js for the robust backend framework
- MongoDB for the flexible database solution
Note: This is a demo application. For production use, consider adding:
- User authentication and authorization
- Rate limiting
- Input validation and sanitization
- Error logging and monitoring
- HTTPS enforcement
- More robust vote tracking (prevent duplicate votes)
249f521 (Initial commit: Online Polling and Voting System with comprehensive README)