0
0
Node.jsframework~20 mins

Health check endpoints in Node.js - 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
1:30remaining
What is the output of this simple health check endpoint?
Consider this Node.js Express health check endpoint. What response does the server send when a GET request is made to /health?
Node.js
import express from 'express';
const app = express();
app.get('/health', (req, res) => {
  res.status(200).json({ status: 'ok' });
});
// Assume server listens correctly
A{"status":"ok"}
BStatus code 404 with empty body
CStatus code 500 with error message
DPlain text response 'ok' with status 200
Attempts:
2 left
💡 Hint
Look at the response method used and the status code set.
📝 Syntax
intermediate
1:30remaining
Which option causes a syntax error in this health check endpoint?
Identify which code snippet will cause a syntax error when defining a health check endpoint in Express.
Aapp.get('/health', (req, res) => { res.status(200).json({ status: 'ok' ) }); });
Bapp.get('/health', (req, res) => res.json({ status: 'ok' }));
Capp.get('/health', (req, res) => { res.send('OK'); });
Dapp.get('/health', function(req, res) { res.sendStatus(200); });
Attempts:
2 left
💡 Hint
Look carefully at the brackets and parentheses in the JSON response.
state_output
advanced
2:00remaining
What is the output when the health check endpoint uses async function but forgets to await?
Given this health check endpoint, what will the client receive when requesting /health?
Node.js
app.get('/health', async (req, res) => {
  const status = checkDatabase(); // async function returning a promise
  res.json({ dbStatus: status });
});

async function checkDatabase() {
  return 'connected';
}
AEmpty JSON object {}
B{"dbStatus":"connected"}
CStatus code 500 with error
D{"dbStatus":{}}
Attempts:
2 left
💡 Hint
Remember what happens if you don't await a promise before sending it in JSON.
🔧 Debug
advanced
2:00remaining
Why does this health check endpoint cause the server to hang?
Examine this health check endpoint code. Why does the server never respond to requests on /health?
Node.js
app.get('/health', (req, res) => {
  checkServiceStatus();
});

function checkServiceStatus() {
  // some async operation but no callback or promise handling
  setTimeout(() => {
    console.log('Service is up');
  }, 1000);
}
AThe console.log throws an error stopping the response.
BThe setTimeout blocks the event loop causing the hang.
CThe endpoint never calls res.send or res.json, so the client waits forever.
DThe endpoint returns a promise but does not handle rejection.
Attempts:
2 left
💡 Hint
Think about what the server must do to finish a request.
🧠 Conceptual
expert
1:30remaining
Which option best describes the purpose of a health check endpoint in a Node.js service?
Choose the most accurate description of why health check endpoints are used in backend services.
ATo authenticate users before allowing access to the main application.
BTo provide a simple URL that external systems can call to verify the service is running and responsive.
CTo expose detailed internal metrics and logs for debugging purposes.
DTo serve the main content of the application to users.
Attempts:
2 left
💡 Hint
Think about monitoring and uptime checks.