This project was proposed by Rocketseat in Next Level Week Expert - Node.js track. The challenge involves the development of the backend for a polling application with data stored using PostgreSQL and Prisma ORM, vote count stored with Redis for quick retrieval, and real-time feedback to connected clients through websockets.
A real-time voting system where users can create a poll and other users can cast their votes. The system generates a ranking among the options and updates the votes in real-time.
You will need Node.js and Docker installed on your machine.
# create .env file based on .env.example
cp .env.example .env
npm i
docker compose up -d
npx prisma migrate dev
npm run dev
Use any tool to test APIs, like Postman, Insomnia or Hoppscotch.
Test the endpoints as per the examples below, where server_base_url
is the same as localhost:3333
.
/polls
: Pass data with title
and options
in the body:
/polls/:pollId
: Pass pollId as queryParam
/polls/:pollId/votes
: Vote on a poll using pollId as queryParam and pollOptionId
in the body
/polls/:pollId/results
: Connect to a poll WebSocket Channel with its Id
# Run docker in detached mode
docker compose up -d
# list containers
docker ps
# Show logs of a container execution
docker logs <container_id>
# stop execution of a container
docker kill <container_id>
# starts a project with prisma
npx prisma init
# applies database migrations in the development environment
npx prisma migrate dev
# opens a GUI to explore and manage your database data
npx prisma studio
During the event, I gained a comprehensive understanding of the fundamental concepts of websockets and their application in real scenarios. In addition, I gained knowledge about integrating Redis as a caching solution, optimizing the vote count in polls and improving the system's operational efficiency.
Esse projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.
Rocketseat
🛠 Front-end
Back-end
Developer Jr.
📍 São Jose dos Campos – SP - Brazil
- Thank you #Rocketseat team