Difference between location and redirection in node.js

What is the use of the res.location () method? I can use res.redirect () to redirect to a specific url and I don't see any changes if I use res.location () before res.redirect ()

+8
redirect
source share
1 answer

They are very similar in their description, but do much more. The easiest way to see the difference is to look at the source .

res.location just sets the response header. It does not set the response status code or does not close the response, so you can write the response body if you want, and you need to call res.end() yourself after.

res.redirect , on the other hand, sets the status to 302, sets the header (using res.location ) and sends a body with a good response, indicating that the user is being redirected, and displays a link if their browser does not automatically redirect them to any that is the reason.

+26
source share

All Articles