A dice game for 2 to 5 players with animated 3D dice, built with Node.js, Express, EJS and MongoDB following the MVC pattern.
| Mode | Players | Saved in the database | Where |
|---|---|---|---|
| Turn-based game | 2 to 5 | Yes | Create Game menu option |
| Free roll | Anyone | No | Free Roll menu option |
- Choose how many players will play (from 2 to 5, three by default); only the fields for the selected players are shown.
- Every visible field is required, and the age is a number.
- The server also limits the number of players to between 2 and 5, so the form can't be bypassed.
Each player takes a turn: press Roll dice to spin the 3D die, then Next player to pass the turn.
![]() 1. Alice and Bruno already rolled. The button passes the turn to Carla. |
![]() 2. After the last roll, the winner is highlighted: Alice wins with 6. |
How a game works:
| Step | What happens |
|---|---|
| First roll | The server rolls all the dice in a single request and saves the game as played |
| Each turn | The current player's die spins and lands on their value |
| Values | Every player gets a different number from 1 to 6, so there is always one winner |
| Last turn | The highest number wins and View results opens the played game |
- The values come from the server, so they can't be changed from the browser.
- When the system's reduce motion setting is on, the dice change face without spinning.
![]() Find by ID: paste a game's unique identifier to open its details. |
![]() All games: every game with its players, status and a link to its details. |
- A played game shows each player's score, the dice on their final values and the winner highlighted.
- View Winner opens the winner's details, and Delete Game removes the game from the database.
Any route that doesn't exist shows a 404 page with a link back to the homepage.
| Step | Action |
|---|---|
| 1 | Open Create Game, choose the number of players and fill in their names and ages |
| 2 | Each player presses Roll dice on their turn |
| 3 | Press Next player to pass the turn |
| 4 | The highest number wins. Press View results to see the played game |
Just want a number? Open Free Roll and roll the die.
| Method | Route | What it does |
|---|---|---|
GET |
/ |
Homepage |
GET |
/createGame |
Form to create a game |
POST |
/createGame |
Creates a game with 2 to 5 players |
GET |
/findGame |
Search by game ID |
GET |
/findGame/:id |
Game details |
PUT |
/startGame/:id |
Rolls the dice and saves the result; returns scores and winnerIndex |
GET |
/winnerGame/:id |
Winner of a game |
GET |
/deleteGame/:id |
Deletes a game |
GET |
/games |
All games |
GET |
/freeRoll |
Free roll mode (no database) |
├── app.js # Express app, routes and MongoDB connection
├── bin/www # Local HTTP server
├── netlify.toml # Netlify build, redirects and function settings
├── netlify/functions/
│ └── server.js # Express app wrapped as a Netlify Function
├── docs/images/ # README screenshots
├── models/
│ ├── game.js # Game: players, status and winner
│ └── player.js # Player: name, age and score
├── controllers/ # One controller per route (create, find, start, winner, delete, games, free roll)
├── routes/ # Express routers
├── views/
│ ├── components/
│ │ ├── header.ejs / footer.ejs
│ │ ├── diceStage.ejs # Turn-based dice row
│ │ └── dieCube.ejs # Reusable 3D die
│ └── *.ejs # Pages
└── public/
├── styles.css # Tailwind build
├── layout.css # Full-height page layout
├── dice.css # 3D dice and roll animation
└── javascripts/app.js # Dice values generator
You need Node.js and a MongoDB Atlas cluster (the free M0 tier works).
-
Clone the repo
# HTTPS git clone https://github.com/nqs48/DiceGame_ADev.git # SSH git clone git@github.com:nqs48/DiceGame_ADev.git
-
Install the dependencies
npm install
-
Create a
.envfile in the root directory with your connection string (it is ignored by git)MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>.mongodb.net/<database>?retryWrites=true&w=majority
-
Run the project
npm start # or: npm run n-start (restarts on file changes)Then open http://localhost:3000.
The site runs on Netlify: static files are served by its CDN and every other route is handled by the Express app as a Netlify Function (see netlify.toml).
- Set the
MONGODB_URIenvironment variable in Project configuration → Environment variables. - In MongoDB Atlas, allow access from
0.0.0.0/0, since Netlify Functions don't have fixed IPs. - To reproduce the Netlify environment locally (Node 20 or newer):
npx netlify-cli dev.
This repository follows Git Flow:
| Branch | Created from | Merged into | Purpose |
|---|---|---|---|
main |
— | — | Production (deployed site) |
develop |
main |
main |
Integration of finished work |
feature/*, docs/* |
develop |
develop |
New features and documentation |
release/x.y.z |
develop |
main and develop |
Release preparation, tagged vX.Y.Z |
hotfix/* |
main |
main and develop |
Urgent production fixes |
Commits follow Conventional Commits.
This project started as a REST API practice of the Sofka Training Campus: a three-player dice game with Node.js, Express and MongoDB, separating views, controllers and models. It was first deployed on Heroku and later moved to Netlify, adding the turn-based 3D dice, games from 2 to 5 players and the free roll mode.
- Node.js & Express
- EJS templates
- MongoDB Atlas with Mongoose
- Tailwind CSS and CSS 3D transforms for the dice
- Netlify Functions with serverless-http
- Git
Distributed under the MIT License. See LICENSE for more information.
|
|
Full Stack Software Engineer · AI-Native Engineering .NET · Node.js · Angular · React · AWS · Azure |








