0
0
Expressframework~10 mins

res.redirect for redirections 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 redirect the user to '/home'.

Express
app.get('/start', (req, res) => {
  res.[1]('/home');
});
Drag options to blanks, or click blank then click option'
Asend
Brender
Credirect
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Using res.render which is for templates
2fill in blank
medium

Complete the code to redirect with a 301 status code to '/new-page'.

Express
app.get('/old-page', (req, res) => {
  res.status(301).[1]('/new-page');
});
Drag options to blanks, or click blank then click option'
Aredirect
Bsend
Cjson
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Not setting the status code before redirect
3fill in blank
hard

Fix the error in the code to properly redirect to '/dashboard'.

Express
app.get('/login', (req, res) => {
  res.redirect [1] '/dashboard';
});
Drag options to blanks, or click blank then click option'
A()
B[]
C{}
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses when calling res.redirect
Using square or curly brackets instead of parentheses
4fill in blank
hard

Fill both blanks to redirect with a 302 status code to '/profile'.

Express
app.get('/user', (req, res) => {
  res.[1]([2], '/profile');
});
Drag options to blanks, or click blank then click option'
Aredirect
Bsend
C302
D301
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Using wrong status code like 301 for temporary redirect
5fill in blank
hard

Fill all three blanks to redirect to '/logout' only if user is logged in.

Express
app.get('/exit', (req, res) => {
  if (req.user) {
    res.[1]([2], [3]);
  } else {
    res.send('Not logged in');
  }
});
Drag options to blanks, or click blank then click option'
Aredirect
B302
C'/logout'
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.redirect
Forgetting quotes around the URL string
Using wrong status code