Challenge - 5 Problems
Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Express health check endpoint?
Consider this Express server code snippet for a health check endpoint. What will the client receive when requesting
/health?Express
import express from 'express'; const app = express(); app.get('/health', (req, res) => { res.status(200).json({ status: 'ok', uptime: process.uptime() }); }); // Assume server listens properly
Attempts:
2 left
💡 Hint
Look at the response method used and the data sent in JSON format.
✗ Incorrect
The endpoint responds with status 200 and a JSON object containing 'status' and 'uptime'. The uptime is a number representing seconds since the process started.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a health check endpoint in Express?
You want to create a health check endpoint at
/health that returns status 200 and JSON {"status":"healthy"}. Which code snippet is correct?Attempts:
2 left
💡 Hint
Remember the order of chaining methods on the response object matters.
✗ Incorrect
Calling res.status(200).json(...) sets the status and sends JSON in one chain. Option A calls json first then status, which does not set status correctly. Option A calls sendStatus which ends response, so json is invalid. Option A sets status but does not chain, so json sends with default status 200 anyway but chaining is preferred.
🔧 Debug
advanced2:00remaining
Why does this health check endpoint cause a runtime error?
Examine this code snippet for a health check endpoint. Why does it cause an error when accessed?
Express
app.get('/health', (req, res) => { res.status(200); res.json({ status: 'ok' }); res.send('Healthy'); });
Attempts:
2 left
💡 Hint
Think about how many times you can send a response per request.
✗ Incorrect
Once res.json sends the response, calling res.send again tries to send another response, which causes a runtime error because the response is already finished.
❓ state_output
advanced2:00remaining
What is the value of
res.statusCode after this health check handler runs?Given this Express health check handler, what will
res.statusCode be after the function executes?Express
app.get('/health', (req, res) => { res.status(503); res.json({ status: 'unavailable' }); });
Attempts:
2 left
💡 Hint
res.status sets the status code before sending the response.
✗ Incorrect
Calling res.status(503) sets the HTTP status code to 503. Then res.json sends the response with that status code. So res.statusCode is 503.
🧠 Conceptual
expert2:00remaining
Which option best explains why health check endpoints should be lightweight and fast?
Health check endpoints are often called frequently by load balancers or monitoring tools. Why is it important that these endpoints are lightweight and fast?
Attempts:
2 left
💡 Hint
Think about how frequent calls to health checks affect server performance and monitoring accuracy.
✗ Incorrect
Health checks are called often to quickly verify if the server is alive. If they are slow or resource-heavy, they can overload the server or cause monitoring systems to think the server is down when it is just slow.