0
0
Expressframework~20 mins

Health check endpoints in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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
APlain text 'ok' with status 200
B{"status":"ok","uptime":<number>} (JSON with uptime as a number)
C404 Not Found error
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Look at the response method used and the data sent in JSON format.
📝 Syntax
intermediate
2: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?
Aapp.get('/health', (req, res) => { res.status(200).json({ status: 'healthy' }); });
Bapp.get('/health', (req, res) => { res.status(200); res.json({ status: 'healthy' }); });
Capp.get('/health', (req, res) => { res.sendStatus(200).json({ status: 'healthy' }); });
Dapp.get('/health', (req, res) => { res.json({ status: 'healthy' }).status(200); });
Attempts:
2 left
💡 Hint
Remember the order of chaining methods on the response object matters.
🔧 Debug
advanced
2: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');
});
Ares.status(200) is called without sending a response body, causing error.
Bres.json cannot be called after res.status.
CMissing return statement causes the endpoint to hang and timeout.
DCalling res.send after res.json causes an error because response is already sent.
Attempts:
2 left
💡 Hint
Think about how many times you can send a response per request.
state_output
advanced
2: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' });
});
Aundefined
B200
C503
D500
Attempts:
2 left
💡 Hint
res.status sets the status code before sending the response.
🧠 Conceptual
expert
2: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?
ABecause slow or heavy health checks can cause false alarms and increase server load unnecessarily.
BBecause health check endpoints must perform full database backups to verify system health.
CBecause health check endpoints should block other requests until they finish.
DBecause health check endpoints should always return detailed logs and metrics.
Attempts:
2 left
💡 Hint
Think about how frequent calls to health checks affect server performance and monitoring accuracy.