Skip to content

Drop in replacement for the HTTP and HTTPS modules to automatically follow redirects. NPM module for Node.js

Notifications You must be signed in to change notification settings

davidjwigg/follow-redirects

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

follow-redirects extends http and https with the ability to follow HTTP redirects painlessly. It does not modify the native modules but instead offers its own http/https modules which inherit from the native modules. If you want to automatically follow redirects, all you need to do is replace:

var http = require('http');

by

var http = require('follow-redirects').http;

Install

npm install follow-redirects

Usage

var http = require('follow-redirects').http;
var https = require('follow-redirects').https;

/* 
 * http and https are just like Node.js' http and https modules except 
 * that they follow redirects seamlessly. 
 */

http.get('http://bit.ly/900913', function (res) {
  res.on('data', function (chunk) {
    console.log(chunk);
  });
}).on('error', function (err) {
  console.error(err);
});

/*
 * You can optionnally pass the maxRedirect option which defaults to 5
 */

https.request({
  host: 'bitly.com',
  path: '/UHfDGO',
  maxRedirects: 3
}, function (res) {
  res.on('data', function (chunk) {
    console.log(chunk);
  });
}).on('error', function (err) {
  console.error(err);
});

License

MIT: http://olalonde.mit-license.org

About

Drop in replacement for the HTTP and HTTPS modules to automatically follow redirects. NPM module for Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published