What is a health check endpoint in an Express app?
A health check endpoint is a simple URL route that returns a quick response to show the app is running and healthy. It helps monitoring tools know the app is alive.
Click to reveal answer
beginner
Why should health check endpoints return fast responses?
Fast responses ensure monitoring tools get quick feedback about the app's status without slowing down the app or causing timeouts.
Click to reveal answer
beginner
Which HTTP status code is commonly used for a successful health check response?
HTTP status code 200 means OK and is commonly used to show the app is healthy.
Click to reveal answer
beginner
How can you create a basic health check endpoint in Express?
Use app.get('/health', (req, res) => res.status(200).send('OK')) to create a simple route that returns 'OK' with status 200.
Click to reveal answer
intermediate
What extra checks can a health check endpoint perform besides just responding?
It can check database connections, external services, or disk space to confirm the app's full health, not just if it is running.
Click to reveal answer
What is the main purpose of a health check endpoint in Express?
ATo confirm the app is running and healthy
BTo serve the main website content
CTo handle user login
DTo store user data
✗ Incorrect
Health check endpoints are designed to quickly confirm the app is alive and working.
Which HTTP method is typically used for health check endpoints?
APUT
BPOST
CGET
DDELETE
✗ Incorrect
GET is used because health checks just request status without changing data.
What status code should a healthy Express app return on its health check endpoint?
A200
B500
C404
D302
✗ Incorrect
200 means OK and signals the app is healthy.
Which of these is NOT a good practice for health check endpoints?
ARespond quickly
BPerform heavy database queries
CReturn simple status messages
DUse a dedicated route like '/health'
✗ Incorrect
Heavy queries slow down health checks and can cause false failures.
How can health check endpoints help in real-life app monitoring?
ABy sending marketing emails
BBy storing user passwords
CBy updating the app automatically
DBy showing if the app is down or slow
✗ Incorrect
Health checks let monitoring systems detect downtime or performance issues.
Explain how to create a simple health check endpoint in Express and why it is useful.
Think about a quick way to tell if your app is alive.
You got /4 concepts.
Describe what additional checks a health check endpoint might perform beyond just responding with 'OK'.
Consider what else affects app health besides just running.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a health check endpoint in an Express app?
easy
A. To serve static files like images
B. To confirm the app is running and responsive
C. To handle user login requests
D. To connect to the database
Solution
Step 1: Understand what a health check endpoint does
A health check endpoint is a simple route that tells if the app is alive and working.
Step 2: Compare options to this purpose
Only To confirm the app is running and responsive matches this purpose. Other options are unrelated to health checks.
Final Answer:
To confirm the app is running and responsive -> Option B
Quick Check:
Health check = Confirm app running [OK]
Hint: Health check endpoints just say if app is alive [OK]
Common Mistakes:
Thinking health check handles user data
Confusing health check with static file serving
Assuming it manages database connections
2. Which of the following is the correct syntax to create a simple health check GET route in Express?
easy
A. app.listen('/health', () => console.log('OK'));
B. app.post('/health', (req, res) => res.send('OK'));
C. app.get('/health', (req, res) => res.send('OK'));
D. app.use('/health', (req, res) => res.send('OK'));
Solution
Step 1: Identify the HTTP method for health check
Health checks use GET requests to check status, so app.get is correct.
Step 2: Check syntax correctness
app.get('/health', (req, res) => res.send('OK')); uses app.get with path '/health' and sends 'OK' response correctly.
Final Answer:
app.get('/health', (req, res) => res.send('OK')); -> Option C
Quick Check:
GET route with res.send('OK') = app.get('/health', (req, res) => res.send('OK')); [OK]
Hint: Health checks use GET routes with res.send('OK') [OK]
Common Mistakes:
Using POST instead of GET
Using app.use instead of app.get
Trying to listen on a route path
3. What will be the output when a client sends a GET request to the following Express route?
app.get('/health', (req, res) => {
res.status(200).send('Service is up');
});
medium
A. HTTP 200 OK with body 'Service is up'
B. HTTP 404 Not Found
C. HTTP 500 Internal Server Error
D. No response, request times out
Solution
Step 1: Analyze the route handler
The route listens for GET on '/health' and sends status 200 with text 'Service is up'.
Step 2: Determine the HTTP response
The client receives status 200 OK and the string 'Service is up' in the response body.
Final Answer:
HTTP 200 OK with body 'Service is up' -> Option A
Quick Check:
Status 200 + send text = HTTP 200 OK with body 'Service is up' [OK]
Hint: res.status(200).send('text') sends 200 OK with that text [OK]
Common Mistakes:
Assuming 404 if route exists
Confusing status codes
Expecting no response or error
4. Identify the error in this health check endpoint code and choose the fix: