0
0
Expressframework~5 mins

res.redirect for redirections in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does res.redirect() do in Express?

res.redirect() sends a response to the browser telling it to go to a different URL. It makes the browser load a new page.

Click to reveal answer
beginner
How do you redirect a user to the homepage '/' using res.redirect()?

Use res.redirect('/'). This tells the browser to go to the root page of the website.

Click to reveal answer
intermediate
What HTTP status code does res.redirect() use by default?

By default, res.redirect() uses status code 302, which means "Found" or temporary redirect.

Click to reveal answer
intermediate
How can you specify a permanent redirect with res.redirect()?

Pass the status code 301 as the first argument, then the URL: res.redirect(301, '/new-url'). This tells browsers the redirect is permanent.

Click to reveal answer
beginner
Can res.redirect() redirect to an external website?

Yes, you can redirect to any URL, including external sites like res.redirect('https://example.com').

Click to reveal answer
What is the default HTTP status code used by res.redirect() in Express?
A500
B301
C404
D302
How do you redirect a user permanently to '/dashboard'?
Ares.redirect(301, '/dashboard')
Bres.redirect(500, '/dashboard')
Cres.redirect(404, '/dashboard')
Dres.redirect('/dashboard')
Which of these is a valid way to redirect to an external site?
Ares.redirect(404, 'https://google.com')
Bres.redirect('/google.com')
Cres.redirect('https://google.com')
Dres.redirect('google.com')
What happens after calling res.redirect() in your route handler?
AThe server sends a redirect response and ends the request.
BThe server continues processing the route.
CThe server throws an error.
DNothing happens until you call <code>res.send()</code>.
Which method is used to redirect in Express?
Ares.sendRedirect()
Bres.redirect()
Cres.go()
Dres.move()
Explain how to use res.redirect() to send a temporary and a permanent redirect in Express.
Think about the status codes and how they affect browser behavior.
You got /3 concepts.
    Describe what happens in the browser and server when res.redirect('/home') is called.
    Consider the communication between server and browser.
    You got /3 concepts.