Key idea
Agents write code that works where they tested it: your laptop. The most common reason it then fails online is one line. The app listens on 127.0.0.1, which only accepts connections from the same machine, or on a port the platform doesn't send traffic to.
Path 1 explains why, in lesson 1.4.3. The short version: online, requests arrive from outside the machine, so the app has to listen on 0.0.0.0 (every address the machine has) and on the port the platform expects.
Find it in the starter
Open server.js and look at the last lines:
app.listen(3000, "127.0.0.1", () => {
console.log("Tasks app listening on http://127.0.0.1:3000");
});
Two things are hard-coded: the loopback address and port 3000. On your laptop both are fine, which is exactly why this kind of bug survives until the first deploy.
Agents write it this way for a good reason: tutorials and dev servers default to localhost, because on a laptop that's the safe choice. The agent ran the app, the loop's observe step saw it answer, and nothing it ran looked like the internet.
If npm start ever fails with EADDRINUSE, something else already uses that port. Pick another one with PORT, which the fix below makes possible.
Fix it
Replace those lines with:
const port = process.env.PORT || 3000;
app.listen(port, "0.0.0.0", () => {
console.log(`Tasks app listening on port ${port}`);
});
The app now listens on every address, and on the port in the PORT environment variable, falling back to 3000 when it isn't set.
Prove both halves on your machine:
PORT=4000 npm start
In another terminal, curl http://localhost:4000/healthz should answer {"status":"ok"}. Stop it, run npm test to check nothing else broke, then commit:
git commit -am "fix: listen on 0.0.0.0 and the PORT variable"
git push
Ask the agent the right question
In your own app, the same bug hides in a framework's start command or config file, not always in a listen call. Ask your agent a question, not for a fix: "Where does this app choose its listen address and port? Show me the lines." Read the answer, then decide the change yourself. Lesson 1.4.3 has the setting for common frameworks.
Isn't 0.0.0.0 risky on my laptop?
On a shared network, 0.0.0.0 lets other devices on the same Wi-Fi reach your dev server. For a toy tasks app that's harmless. For anything with real data, you can read the address from a variable too, such as HOST, default it to 127.0.0.1, and set HOST=0.0.0.0 only where the app is deployed.
Check yourself