0
0
Expressframework~10 mins

Why routing matters in Express - Test Your Understanding

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

Complete the code to create a basic route that responds with 'Hello World!'.

Express
app.[1]('/', (req, res) => {
  res.send('Hello World!');
});
Drag options to blanks, or click blank then click option'
Apost
Bget
Clisten
Duse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for a simple page request.
Using 'listen' which is for starting the server, not routing.
2fill in blank
medium

Complete the code to add a route that handles POST requests to '/submit'.

Express
app.[1]('/submit', (req, res) => {
  res.send('Form submitted');
});
Drag options to blanks, or click blank then click option'
Aput
Bget
Cpost
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' for data submission routes.
Confusing 'put' or 'delete' which are for updating or deleting data.
3fill in blank
hard

Fix the error in the route definition to correctly handle a DELETE request.

Express
app.[1]('/item/:id', (req, res) => {
  res.send(`Deleted item ${req.params.id}`);
});
Drag options to blanks, or click blank then click option'
Adelete
Bget
Cput
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' or 'post' instead of 'delete' for deletion routes.
Confusing 'put' which is for updating data.
4fill in blank
hard

Fill both blanks to create a route that updates an item using PUT and sends a JSON response.

Express
app.[1]('/item/:id', (req, res) => {
  res.[2]({ message: `Updated item ${req.params.id}` });
});
Drag options to blanks, or click blank then click option'
Aput
Bsend
Cjson
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'put' for updates.
Using res.send() instead of res.json() when sending JSON.
5fill in blank
hard

Fill all three blanks to create a route that handles GET requests with a dynamic parameter and sends a custom message.

Express
app.[1]('/user/:name', (req, res) => {
  const userName = req.params.[2];
  res.[3](`Hello, ${userName}!`);
});
Drag options to blanks, or click blank then click option'
Aget
Bname
Csend
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'name' for the parameter.
Using 'post' instead of 'get' for the route method.
Using res.json() instead of res.send() for a simple text message.