follow-redirects
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Follow-Redirects is a drop-in replacement for Node's http
and https
modules providing automatic redirection following features. It's an incredibly useful package when you want your HTTP or HTTPS request methods to seamlessly follow redirects without any additional coding required.
Follow-Redirects is simple to use. Here's a basic usage example:
const { http, https } = require('follow-redirects');
http.get('http://bit.ly/900913', response => {
response.on('data', chunk => {
console.log(chunk);
});
}).on('error', err => {
console.error(err);
});
In this code, an HTTP GET request is made. If the requested URL redirects to another URL, the request will automatically follow the redirection.
To inspect the final redirected URL, you can use the responseUrl
property. Here's an example:
const request = https.request({
host: 'bitly.com',
path: '/UHfDGO',
}, response => {
console.log(response.responseUrl);
// 'http://duckduckgo.com/robots.txt'
});
request.end();
In this case, the responseUrl
will return the final URL where the original URL was redirected to. If no redirection took place, responseUrl
will be the original request URL.
The comprehensive Follow-Redirects documentation can be found on their GitHub repo. It includes comprehensive details on usage, options, advanced usage, and more, making it easier for users to understand and implement the package accurately.