0
0
Expressframework~10 mins

res.status for status codes 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 set the HTTP status to 404.

Express
app.get('/notfound', (req, res) => {
  res.status([1]).send('Page not found');
});
Drag options to blanks, or click blank then click option'
A404
B200
C500
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 which means OK instead of 404.
Using 500 which means server error.
Using 302 which means redirect.
2fill in blank
medium

Complete the code to send a 201 status code after creating a resource.

Express
app.post('/create', (req, res) => {
  // resource creation logic
  res.status([1]).send('Created');
});
Drag options to blanks, or click blank then click option'
A404
B400
C201
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 which means bad request.
Using 404 which means not found.
Using 500 which means server error.
3fill in blank
hard

Fix the error in setting the status code to 500 for server error.

Express
app.get('/error', (req, res) => {
  res.status([1]).send('Server error occurred');
});
Drag options to blanks, or click blank then click option'
A'500'
B500
Cstatus(500)
Dres.status(500)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the status code as a string like '500'.
Calling status(500) inside the argument.
Passing res.status(500) inside the argument.
4fill in blank
hard

Fill both blanks to set status 403 and send a message 'Forbidden'.

Express
app.get('/forbidden', (req, res) => {
  res.status([1]).[2]('Forbidden');
});
Drag options to blanks, or click blank then click option'
A403
Bsend
Cjson
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 instead of 403 for forbidden.
Using json instead of send when sending plain text.
5fill in blank
hard

Fill all three blanks to set status 302, redirect to '/login', and end the response.

Express
app.get('/redirect', (req, res) => {
  res.status([1]).[2]('/login').[3]();
});
Drag options to blanks, or click blank then click option'
A404
Bredirect
Cend
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 instead of 302 for redirect.
Using send instead of redirect.