0
0
Expressframework~10 mins

app.all and app.use for catch-all 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 catch-all route using app.all.

Express
app.[1]('*', (req, res) => {
  res.send('Catch-all route');
});
Drag options to blanks, or click blank then click option'
Aall
Buse
Cget
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.get or app.post which only handle specific HTTP methods.
Using app.use without specifying the path correctly.
2fill in blank
medium

Complete the code to create a catch-all middleware using app.use.

Express
app.[1]((req, res) => {
  res.status(404).send('Not Found');
});
Drag options to blanks, or click blank then click option'
Aall
Bpost
Cget
Duse
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.all instead of app.use for middleware.
Specifying a path when you want a catch-all middleware.
3fill in blank
hard

Fix the error in the catch-all route that should handle all HTTP methods for any path.

Express
app.[1]('*', (req, res) => {
  res.send('This is a catch-all route');
});
Drag options to blanks, or click blank then click option'
Aall
Buse
Cget
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.use with a path, which does not behave as a route handler.
Using app.get or app.post which only handle specific methods.
4fill in blank
hard

Fill both blanks to create a catch-all middleware that sends a 404 status and message.

Express
app.[1]((req, res) => {
  res.status([2]).send('Page not found');
});
Drag options to blanks, or click blank then click option'
Ause
Ball
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.all instead of app.use for middleware.
Sending status 500 which means server error, not 'not found'.
5fill in blank
hard

Fill all three blanks to create a catch-all route that logs the method, path, and sends a 404 response.

Express
app.[1]('*', (req, res) => {
  console.log(req.[2], req.[3]);
  res.status(404).send('Not Found');
});
Drag options to blanks, or click blank then click option'
Aall
Bmethod
Cpath
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.url instead of req.path which includes query strings.
Using app.use instead of app.all for route handlers.