Lost and Found — Node.js

Build Mas Candra's lost and found Node server: modules, SQLite, auth, upload, tests and WebSocket. 16 levels, right in the browser.

What the levels ask

  1. Monday morning, Mr. Candra opens Pos Temuan, the village lost-and-found at the mouth of Pinang Lane. His laptop sets "type": "module" in package.json, so server.mjs is an ES module. This morning the server refuses to start. Pick how to load Express so the server comes up and answers the first request.
  2. Tuesday. Mr. Candra does not want to write the port number straight into the code, because when the server is deployed elsewhere its port is set from outside. The photo folder must be right on any laptop too, not stitched from his own machine path. Pick the port source and the base of the photo folder so both are right.
  3. Wednesday. The photo folder must always sit inside the Pos Temuan folder, wherever the server is run from. Mr. Candra ran his server from another folder this morning, and the photo folder was built in the wrong place. Pick how to build the photo folder path from BASE, the module’s base.
  4. Thursday. On day one the found-items log catatan.json is empty, and the file does not exist yet. The server must stay up and answer an empty list of items, not die when it fails to read a file that is not there. Pick how to read the log file.
  5. Friday. Three villagers report lost items one after another, and each item needs a number that is unique and hard to guess. Mr. Candra is unsure between randomUUID, a number from the clock, and a short random string. Pick the source of the item number.
  6. Saturday. Mr. Candra adds a live board: every phone that opens the board adds one temuan listener to an EventEmitter. After a dozen phones open it, Node prints a warning. Pick how to add the listener so the board does not leak.
  7. Mrs. Sa'diyah reports a lost wallet, and her name has an apostrophe. In a real SQLite database through node:sqlite, how you insert the report decides whether her name is stored whole or the query breaks. Pick how to insert the report into the temuan table.
  8. One claim writes two things: the item is marked as taken, and a record of who took it is added. Both must be saved together or both cancelled. When a second claim on the same item makes its record fail, pick how to write so the database does not become inconsistent.
  9. Two villagers claim the same wallet almost at once. The last guard against an item being claimed twice is the database itself. Pick the definition of the barang_id column in the klaim table so the second claim is refused.
  10. So only the owner can claim a valuable item, villagers register a password. That password must not be stored as is. Two villagers happen to use the same password. Pick how to store the password.
  11. Mrs. Sari logs in to claim her item. Two things decide how safe it is: how the password is checked against the stored hash, and where the login session is kept. Pick how to check the password and where to keep the session.
  12. Mrs. Sari is done and presses log out. Logging out must really end her session, not just clear the cookie on the phone: if her session is still alive on the server, the old session id still works. Pick what logout does.

And more, 16 levels in all.