This project, developed during the Rocketseat Next Level Week event, Expert edition, enables the creation of polls and facilitates voting on them. The polls are stored in a PostgreSQL database, with the application utilizing the Prisma ORM for this purpose. Additionally, the API incorporates a Websocket connection, through which updates on individual poll votes are broadcasted each time a user casts their vote. Redis is employed to manage the rankings of the poll votes.
Node v20.10.0
yarn install
Create a new .env
file inside the project root, and define your database URL using the content below and replacing the <user
and <password
by the database user and password respectively.
.env
:
DATABASE_URL="postgresql://<user>:<password>@localhost:5432/polls?schema=public"
docker compose up -d
This will start a PostgreSQL instance and a Redis instance on Docker.
This will run all migrations creating the tables and other configs inside the database.
yarn prisma db push
yarn dev
The API will be running on http://localhost:3333
and websocket on ws://localhost:3333
.
Route | Method | Protocol | Description |
---|---|---|---|
/polls | POST | HTTP | Create a new poll. |
/polls/:pollId | GET | HTTP | Get a single poll. |
/polls/:pollId/vote | POST | HTTP | Vote on a poll option. |
/polls/:pollId/results | -- | WS | Open a WS connection to receive votes results. |