follow-redirects

A drop-in replacement for Node's http and https modules that transparently follows redirects with zero runtime dependencies.

Library
npm
v1.16.0
580stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity8
Maintenance32
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture82
Code Quality85
Innovation58
Learning Curve55

follow-redirects wraps Node.js’s native http and https modules so that request() and get() calls behave exactly like the built-ins, except that 3xx redirect chains are followed automatically instead of being surfaced to the caller as a response the app has to re-request itself. It exposes the final redirected URL on response.responseUrl, can optionally record the full chain of hops via trackRedirects, and strips sensitive headers like Authorization, Cookie, and Proxy-Authorization whenever a redirect crosses a host or protocol boundary, closing a class of credential-leak bugs that hand-rolled redirect-following code commonly misses.

Because it mirrors the native module APIs almost exactly, it slots underneath higher-level HTTP clients rather than being used directly by most application code — most notably it is the redirect engine inside axios, one of the most widely used HTTP clients in the Node ecosystem, which is reflected in its enormous weekly download count relative to its small, single-purpose codebase.

What You Get

  • Drop-in http and https replacements with identical request()/get() signatures, so existing code needs no rewrite beyond the import
  • Automatic following of 3xx redirect chains, with the final URL exposed on response.responseUrl
  • Configurable maxRedirects and maxBodyLength guards that raise typed errors (ERR_FR_TOO_MANY_REDIRECTS, ERR_FR_MAX_BODY_LENGTH_EXCEEDED) instead of hanging or silently truncating
  • Automatic stripping of sensitive headers (Authorization, Cookie, Proxy-Authorization, plus any caller-supplied sensitiveHeaders) when a redirect crosses hosts or protocols
  • A beforeRedirect hook to inspect or rewrite outgoing options on each hop, or abort the request by throwing
  • A wrap() function to layer redirect-following on top of custom http/https-shaped implementations, which is how caching or instrumented HTTP layers can add redirect support

Common Use Cases

  • Powering the redirect-following logic inside higher-level HTTP clients (this is how axios follows redirects internally)
  • Fetching URLs from user-submitted or third-party sources where the final destination after redirects is unknown and needs to be inspected before trusting the response
  • Any server-side proxy or crawler that needs bounded, safe redirect-following without leaking auth headers to a different origin
  • Replacing raw http.request/https.request calls in legacy code where redirects were previously handled manually with ad hoc loops

Under The Hood

Architecture The library centers on a single RedirectableRequest class that extends Node’s Writable stream and wraps a native http/https request object rather than reimplementing socket handling. Native response and lifecycle events (abort, aborted, connect, error, socket, timeout) are re-emitted onto the wrapping instance through a small event-handler table (index.js), so callers see a single consistent EventEmitter interface regardless of how many hops occur underneath. _processResponse inspects each native response for a redirect status code, applies _sanitizeOptions and the sensitive-header regex filter built from sensitiveHeaders, and either resolves the visible response or issues the next hop, tracking hop count in _redirectCount and, optionally, hop history in _redirects. Distinct error subclasses (InvalidUrlError, RedirectionError, TooManyRedirectsError, MaxBodyLengthExceededError, WriteAfterEndError) carry stable error codes so callers can branch on failure type rather than parsing messages. A top-level wrap() factory produces http/https-shaped module replacements bound to any underlying protocol implementation, which is what lets custom/cached transports gain redirect support without touching this internal logic.

Tech Stack Zero runtime dependencies — only Node’s own url, http, https, stream, and assert core modules are required, with debug wired in as an optional peer dependency purely for DEBUG=follow-redirects log output. The package ships as plain CommonJS (index.js, with http.js/https.js as one-line re-export shims for bundler aliasing) and declares engines.node >= 4.0, reflecting its role as low-level infrastructure that must run in whatever Node version its dependents target. Dev tooling is limited to what’s needed to test and lint: mocha + nyc for tests and coverage, eslint for linting, and express only as an in-process test server.

Code Quality Test coverage is extensive relative to the codebase size: a single 2,355-line test/test.js exercises over 100 cases covering redirect-count limits, body-length limits, cross-protocol redirects, method downgrades on 301/302/303, header sanitization across origins, the beforeRedirect hook, timeouts, and agent selection per protocol, run under nyc for coverage reporting. ESLint extends eslint:recommended with a substantial set of stylistic and best-practice rules enabled explicitly. CI (GitHub Actions) runs both lint and a test matrix spanning roughly twenty Node.js versions from 4.x through the current release, which is unusually broad and signals a deliberate commitment to long-tail compatibility for a package this deep in the dependency tree. Error handling is explicit throughout, using the typed error classes described above rather than generic thrown strings or swallowed exceptions.

What Makes It Unique The library’s core value isn’t a novel redirect algorithm — following 3xx chains is a well-understood problem — but the completeness of its safety handling: automatic, non-optional stripping of credential-bearing headers on cross-origin or cross-protocol hops is a real security property that many simpler or hand-rolled redirect-following implementations omit entirely, and the configurable maxRedirects/maxBodyLength guards with typed errors give callers a way to fail safely rather than hang. Its near-total API parity with Node’s native http/https modules, combined with the wrap() escape hatch for custom transports, is what has made it the de facto redirect layer beneath other popular HTTP clients rather than a library developers reach for directly.

Used by 7 apps in this directory

TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
JavaScript
99%
GPL 3.0

homepage

Monitoring · Productivity

32,445

A fast, fully static, and secure self-hosted startpage with Docker service discovery and integrations for over 160 services.

View details
91
Repo Health
86
Technical
72
Dependency
Built with
JavaScript99%
Updated today
TypeScript
76%
Other

Joplin

Note Taking

56,257

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
61
Dependency
Built with
TypeScript76%
JavaScript14%
Updated yesterday
TypeScript
97%
Other

nango

Developer Tools · Automation · Authentication

11,746

Build product integrations with AI using 800+ APIs — auth, proxy, and TypeScript functions on production-grade infrastructure.

View details
93
Repo Health
85
Technical
68
Dependency
Built with
TypeScript97%
Updated 3 days ago
JavaScript
98%
Apache 2.0

Parse Server

Developer Tools · Databases

21,414

Self-hosted Backend-as-a-Service for Node.js with REST, GraphQL, real-time Live Query, cloud code, and pluggable adapters for any infrastructure.

View details
98
Repo Health
81
Technical
78
Dependency
Built with
JavaScript98%
Updated yesterday
TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,316

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
95
Repo Health
75
Technical
70
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
JavaScript
100%
AGPL 3.0

Social Analyzer

Security

23,945

Find and analyze a person's digital footprint across 1000+ social media platforms using multi-layer detection, OCR, and metadata extraction.

View details
42
Repo Health
52
Technical
68
Dependency
Built with
JavaScript100%
Updated 7 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search