Over the last three sections, you got the Elm Lane walks API ready one piece at a time, with a lesson for each change. Priya now wants her booking page in front of all six households. For that, the co-op needs the whole API working together, and this time you build it without a walkthrough.
In this project, you’ll build that API from a fresh copy of the starting project. The brief comes with checks that list the requests to send and the responses and log lines your API must produce, so you’ll know exactly what “ready” means. Two graded exercises then test it step by step. Start with what Priya asked for.
What Priya Needs
Priya’s page works only if the API behind it is set up for the machine it runs on, lets her page in, and leaves a trail when something goes wrong. Here’s her request in the co-op’s words:
- Settings per machine: Each neighbor who runs the API sets the port, the data file, and the page’s address in their own
.envfile, never in the code. If a required setting is missing or a value is mistyped, the API stops at startup and displays the variable’s name before anyone books a walk. - Open to the booking page only: The page on
http://localhost:5173can list the walks and book one. A page on any other origin gets no permission to read the answers. - A log you can follow: Every request leaves one JSON finish line with its request ID, status, and duration. A server error adds one more line with its stack, and the stack never goes out in the response. No line ever holds an owner’s phone number.
The API needs three settings, the ones Priya’s request depends on:
| Variable | Required? | Value on your machine |
|---|---|---|
PORT |
No, defaults to 3000 | 3000 |
DATA_FILE |
Yes | data/walks.json |
ALLOWED_ORIGIN |
Yes | http://localhost:5173 |
PRETTY_JSON and LOG_LEVEL from the lessons are welcome extras. If you add LOG_LEVEL, then run the checks with LOG_LEVEL=info, because a higher level hides the log lines for successful requests shown in check 4.
Your own copy already does most of this, but building from a brief is a different skill from following a lesson. You decide the order, and the checks tell you when you’re done.
The course download has the starting project and the finished code. Copy the 00-intro/starting-project folder to a new folder, open a terminal there, and run npm install. Keep the finished code closed until you’ve tried each step on your own.