/NodeJs_Proj

NLW event, a system was created with the Rocketseat Team, a real-time voting system where users can create a poll and other users can cast their votes.

Primary LanguageTypeScript

💻 NLW Expert - Node.js


Docker Fastify Node.js Typescript
Redis PostgreSQL PrismaORM WebSockets

About

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.

How to Run

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

How to test

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.

💻 Project Vscode

Home Image

💻 Project Docker

Home Image

💻 Project BD_Prisma_Studio

Home Image

Create a Poll

/polls: Pass data with title and options in the body:

Get Poll Data

/polls/:pollId: Pass pollId as queryParam

Vote on Poll

/polls/:pollId/votes: Vote on a poll using pollId as queryParam and pollOptionId in the body

💻 Project hoppscotch_Back

Home Image

Realtime Feedback

/polls/:pollId/results: Connect to a poll WebSocket Channel with its Id

💻 Project hoppscotch_Back_Conection

Home Image

Useful Commands:

Docker

# 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>

💻 Project Docker

Home Image

Prisma

# 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

💻 Project BD_Prisma_Studio

Home Image

🛠 Tecnologias | Tecnologias

The following tools were used in building the project


Comments 😃

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.


📝 Licença

Esse projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.


✒️ Authors

Rocketseat

  • My LinkedIn - Linkedin Badge

Contact

🛠 Front-end Back-endDeveloper Jr.
📍 São Jose dos Campos – SP - Brazil

LinkedIn Badge  Gmail Badge  Discord Badge  GitHub Badge 



🎁 Acknowledgements and dedications

  • Thank you #Rocketseat team