Mastering Timers, Routing Order, and API Testing 掌握定时器、路由顺序和 API 测试
In Express, code runs top-to-bottom. If you define a "catch-all" (404 handler) BEFORE your routes, it intercepts everything! 在 Express 中,代码从上到下运行。如果你在路由之前定义了一个“捕获所有”(404 处理程序),它会拦截所有请求!
Allows frontend (browser) to talk to backend on different ports. Without this, browser blocks requests. 允许(浏览器)前端与不同端口的后端通信。没有这个,浏览器会阻止请求。
Parses incoming JSON payloads in req.body. Without this,
req.body is undefined.
解析 req.body 中的传入 JSON 载荷。没有这个,req.body 为 undefined。
Logger. Prints "GET /v1/users 200" to your terminal. Crucial for debugging. 日志记录器。在终端打印 "GET /v1/users 200"。对调试至关重要。
When using setTimeout in Express (e.g. for scheduled deletion),
you must catch errors INSIDE the callback.
在 Express 中使用 setTimeout(例如用于计划删除)时,必须在回调内部捕获错误。
When clearing data (RESET), you MUST also clearTimeout() all
active timers. Otherwise, they might run later and try to delete non-existent data!
清除数据(重置)时,必须同时 clearTimeout()
所有活动定时器。否则,它们稍后可能会运行并尝试删除不存在的数据!
DELETE /v1/clear before EVERY test to ensure
isolation.
至关重要!在每个测试之前调用 DELETE /v1/clear 以确保隔离。
Take the comprehensive 40-question quiz covering all Day 3 topics! 参加涵盖 Day 3 所有主题的 40 题综合测验!
Start Day 3 Quiz → 开始 Day 3 测验 →