Handle Redirect Response
NodeJS
Medium
3 views
Problem Description
Detect 301/302 and print the Location header (demo).
Output Format
Print URL or empty.
Constraints
Mock response headers object.
Official Solution
const res = { statusCode: 301, headers: { location: 'https://meetcode.com' } };
if (res.statusCode === 301 || res.statusCode === 302) {
console.log(res.headers.location || '');
} else {
console.log('');
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!