Due: Tuesday, 12/1/26, before class.
Build a small game where your server talks to two things outside of it: a free public API that supplies the game (words, Pokémon, cards, or trivia questions), and a MongoDB Atlas database that saves everyone's results. A player uses buttons or a form on your page, your server does the work, and the page updates.
Every piece of this is something we've done in class: fetch to our own server, routes in
Express, POST with a JSON body, calling an outside API from the server, secrets in .env,
saving and reading with MongoDB, and hosting on Render. This assignment puts them together.
Useful examples: Calling the Gemini API from Our Server (server calls an outside API and sends the result to the page) and the MongoDB example from class on Friday 11/20.
Pick one of these three, or make up your own game using any API you want. The three APIs below are free and need no API key. If the API you choose needs a key, that's fine: keep it secret the same way as your MongoDB connection string (see requirement 3).
Two Pokémon appear, along with a random stat, like "Which one has more speed?" or "Which one has more HP?" Every right answer adds to your streak, and every round asks about a different random stat (if they tie, either answer counts). One wrong answer ends the game, and your streak goes on the leaderboard.
https://pokeapi.co/api/v2/pokemon/ID, where ID is a number from 1 to 1025. The answer
includes name, a picture in sprites.front_default, and a
stats array with six stats (hp, attack, defense,
special-attack, special-defense, speed). Each one looks like
{ base_stat: 90, stat: { name: "speed" } }. You can also use weight and
height.
stats), and sends back what the page
needs. A POST route that saves a score. A GET route for the leaderboard.
Higher or lower with a real shuffled deck. You see a card. Will the next one be higher or lower? Keep going until you're wrong.
https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1 shuffles a new deck and
gives you its deck_id. Then
https://deckofcardsapi.com/api/deck/DECK_ID/draw/?count=1 draws a card, with an
image, value, and suit.
Answer multiple-choice questions. Your score goes on a leaderboard that everyone shares.
https://opentdb.com/api.php?amount=10&type=multiple gives 10 questions,
each with question, correct_answer, incorrect_answers,
category, and difficulty.
Here are a few more APIs to look at. Every one of these works as of 11/17/26.
| API | What it gives you |
|---|---|
| Free Dictionary | Definitions of any English word, or a 404 if it isn't one |
| TheMealDB | Recipes from around the world, with photos and the country they're from |
| Open Library | Millions of books, with covers and publication years |
| JokeAPI | Jokes, by category (use safe-mode) |
| Gemini (needs a free key, like class on 11/17) | An AI that can write or judge almost anything |
Make a new 08-api-game folder in your assignments folder. Folder and file names
must match exactly:
csc336-fall2026/
└── assignments/
└── 08-api-game/
├── README.md
├── .gitignore
├── .env (on your computer only, never pushed)
├── package.json
├── package-lock.json
├── server.js
└── public/
├── index.html
├── style.css
└── script.js
cd into 08-api-game and run:
npm install express mongodb dotenv
Add "type": "module" to package.json, like Assignment 7. Make a
.gitignore with these two lines:
node_modules
.env
.env:
MONGODB_URI=mongodb+srv://USERNAME:PASSWORD@cluster0.xxxxx.mongodb.net/
In Atlas, under Network Access, allow access from anywhere
(0.0.0.0/0). Otherwise Render can't connect.
script.js only ever fetches
your own routes, and your server fetches the outside API and sends back what the
page needs. If your API needs a key, put it in .env (for example
API_KEY=...), read it with process.env.API_KEY, and add it to Render's
Environment tab too. Never put a key in your code, and never in script.js.
fetch from your server and update the page with what comes
back. No page reloads.
express.json() and req.body)
and saves it with insertOne. For example: a name and a score, or a new word and who added
it.
find with a filter (for example
{ category: "History" }) or a sort (for example highest score first), and sends the
results to the page. The page shows them (a leaderboard, best runs, everyone's captions).
node server.js and play your game at
http://localhost:3000. Check your data in Atlas
under Browse Collections.
assignments/08-api-game. Your
.env isn't pushed, so Render doesn't have it: in your service's
Environment tab, add MONGODB_URI with the same connection string.
Use const port = process.env.PORT || 3000; like before.
README.md with your linkREADME.md in 08-api-game with your Render link at the
top, like:
https://yourname-api-game.onrender.com
GitHub shows this file when someone opens your folder, which is how I'll find your game.
If you couldn't get it working (on Render, or at all), say so at the top instead,
and write up what you did get working, what isn't working, and what you tried to fix it. An honest
write-up of a game that's partly working is much better than nothing.
server.js and
script.js explaining what each part does.
@, :, or
/ in your database password break the connection string. Use a password with only
letters and numbers.
.env is in the same folder you run
node server.js from, that the password in the string is right (no
< > left around it), and that Network Access allows your IP.
"10" > "9" is false! Use Number(...) before you
compare or save a score.
"8",
"KING", and "ACE". You'll need to turn those into numbers yourself.
response_code: 5 and no questions, so get all your questions in one request.
Questions also come with codes like ' for '. Putting them on the
page with innerHTML shows them correctly.
Do not use ChatGPT, Copilot, Claude, or any other generative AI tool to write any part of this assignment. Whatever you do, remember that your goal should be to understand 100% of the code that you turn in.
Nothing to submit directly. Push your 08-api-game folder (without .env or
node_modules), make sure your Render link works, and make sure your README.md
has the link (or your write-up of what works and what doesn't).