0
0
Expressframework~10 mins

Health check endpoints in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic health check route that responds with 'OK'.

Express
app.get('/health', (req, res) => {
  res.status([1]).send('OK');
});
Drag options to blanks, or click blank then click option'
A404
B302
C500
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 or 500 which indicate errors.
Forgetting to send a response.
2fill in blank
medium

Complete the code to add a JSON response with a status message in the health check endpoint.

Express
app.get('/health', (req, res) => {
  res.status(200).json({ status: [1] });
});
Drag options to blanks, or click blank then click option'
A'error'
B'ok'
C'fail'
D'pending'
Attempts:
3 left
💡 Hint
Common Mistakes
Using negative status messages like 'error' or 'fail'.
3fill in blank
hard

Fix the error in the health check route to correctly send a JSON response.

Express
app.get('/health', (req, res) => {
  res.send([1]);
});
Drag options to blanks, or click blank then click option'
A{ status: 'ok' }
B'OK'
C200
Dres.status(200)
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a string instead of an object.
Passing a number or status code directly to send.
4fill in blank
hard

Fill both blanks to create a health check endpoint that responds with status 200 and JSON { status: 'healthy' }.

Express
app.get('/health', (req, res) => {
  res.status([1]).json({ status: [2] });
});
Drag options to blanks, or click blank then click option'
A200
B'healthy'
C'ok'
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status codes like 500.
Using 'ok' instead of 'healthy' for the status message.
5fill in blank
hard

Fill all three blanks to create a health check endpoint that responds with status 200, JSON { status: 'ok' }, and logs 'Health check passed' to the console.

Express
app.get('/health', (req, res) => {
  console.log([1]);
  res.status([2]).json({ status: [3] });
});
Drag options to blanks, or click blank then click option'
A'Health check passed'
B200
C'ok'
D'Server running'
Attempts:
3 left
💡 Hint
Common Mistakes
Logging wrong messages.
Using incorrect status codes or JSON values.