What is the use of res.location() method? I can use res.redirect() to redirect to a particular URL and i cannot see any change if i use res.location() before res.redirect()<
They are very similar in their description, but one does much more. The easiest way to see the difference is look at the source.
res.location
just sets the response header. It does not set a response status code or close the response, so you can write a response body if you want, and you have to call res.end()
on your own after.
res.redirect
on the other hand sets the status to 302, sets the header (using res.location
) and sends a nice response body saying that the user is being redirected, and renders a link if their browser doesn't automatically redirect them for some reason.