Welcome to the Polls Project! This interactive voting platform enables users to create and participate in polls, with real-time updates on voting outcomes.
- Create Polls: Initiate new polls with multiple options.
- Vote: Participate in existing polls by casting votes.
- Real-Time Results: Dynamically update and display poll results.
- src/: Contains the source code for the project.
- prisma/: Database schema and migrations.
- docker-compose.yml: Configuration for Docker containers.
- .env.example: Example environment variables.
- Docker
- Node.js
Clone the repository:
git clone https://github.com/gufvr/polls.git
Navigate to the project directory:
cd polls
Install dependencies:
npm install
Set up PostgreSQL and Redis:
docker-compose up -d
Copy the environment example file and configure:
cp .env.example .env
Start the application:
npm run dev
Create a New Poll
POST /polls
Request body:
{
"title": "What's the best Node.js framework?",
"options": [
"Express",
"Fastify",
"NestJS",
"HapiJS"
]
}
Response body:
{
"pollId": "194cef63-2ccf-46a3-aad1-aa94b2bc89b0"
}
Retrieve a Poll
GET /polls/:pollId
Response body:
{
"poll": {
"id": "e4365599-0205-4429-9808-ea1f94062a5f",
"title": "What's the best Node.js framework?",
"options": [
{
"id": "4af3fca1-91dc-4c2d-b6aa-897ad5042c84",
"title": "Express",
"score": 1
},
{
"id": "780b8e25-a40e-4301-ab32-77ebf8c79da8",
"title": "Fastify",
"score": 0
},
{
"id": "539fa272-152b-478f-9f53-8472cddb7491",
"title": "NestJS",
"score": 0
},
{
"id": "ca1d4af3-347a-4d77-b08b-528b181fe80e",
"title": "HapiJS",
"score": 0
}
]
}
}
Vote on a Poll
POST /polls/:pollId/votes
Request body:
{
"pollOptionId": "31cca9dc-15da-44d4-ad7f-12b86610fe98"
}
WebSockets
WebSocket /polls/:pollId/results
Message:
{
"pollOptionId": "da9601cc-0b58-4395-8865-113cbdc42089",
"votes": 2
}
This project is open-source and available under the MIT License.