Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including fast-proxy with all npm packages installed. Try it out:

var fastProxy = require("fast-proxy")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fast-proxy v1.7.0

Forward your HTTP request to another server.


NPM version

Node.js framework agnostic library that enables you to forward an http request to another HTTP server. Supported protocols: HTTP, HTTPS, HTTP2

This library was initially forked from fastify-reply-from:

fast-proxy powers: 🚀


npm i fast-proxy


The following examples describe how to use fast-proxy with restana:


const { proxy, close } = require('fast-proxy')({
  base: ''
  // options
const gateway = require('restana')()

gateway.all('/service/*', function (req, res) {
  proxy(req, res, req.url, {})


Remote service:

const service = require('restana')()
service.get('/service/hi', (req, res) => res.send('Hello World!'))



Benchmark scripts can be found in benchmark folder.

fast-proxy is fast with F

wrk -t8 -c50 -d20s
  • fast-proxy-undici/0http: Requests/sec 19014.13 (HTTP pipelining = 10)
  • fast-proxy/0http: Requests/sec 17791.10
  • fast-proxy/restana: Requests/sec 17013.53
  • fast-proxy-undici/0http: Requests/sec 15320.76 (HTTP pipelining = 1)
  • fastify-reply-from: Requests/sec 12056.81
  • http-proxy: Requests/sec 408.97




Set the base URL for all the forwarded requests. Will be required if http2 is set to true Note that path will be discarded.


Set to true if target server is http2 enabled.


Set to true to use undici instead of require('http'). Enabling this flag should guarantee 20-50% more throughput.

This flag could controls the settings of the undici client, like so:

  base: 'http://localhost:3001/',
  undici: {
    connections: 100,
    pipelining: 10


The number of parsed URLs that will be cached. Default: 100.

Use value = 0 to disable the caching mechanism

requests.http and requests.https

Allows to optionally overwrite the internal http and https client agents implementation. Defaults: http and https.

For example, this could be used to add support for following redirects, like so:

  requests: {
    http: require('follow-redirects/http'),
    https: require('follow-redirects/https')

If using undici or http2 this settings are ignored!


Defaults to 1 minute, passed down to [http.Agent][http-agent] and [https.Agent][https-agent] instances.


Defaults to 2048 sockets, passed down to [http.Agent][http-agent] and [https.Agent][https-agent] instances.


Defaults to true, passed down to [https.Agent][https-agent] instances. This needs to be set to false to reply from https servers with self-signed certificates.

Extended configurations

Other supported configurations in can also be part of the opts object.


Optional "on close resource release" strategy. You can link this to your application shutdown hook as an example.

proxy(originReq, originRes, source, [opts])

Enables you to forward an http request to another HTTP server.

  originReq,                          // http.IncomingMessage 
  originRes,                          // http.ServerResponse
  req.url,                            // String -> remote URL + path or path if base was set
  {}                                  // Options described below



Optionally indicates the base URL for the current request proxy. When used, the global base config is overwriten.

This configuration value is ignored when using HTTP2.

onResponse(req, res, stream)

Called when an http response is received from the source. The default behavior is pump(stream, res), which will be disabled if the option is specified.

rewriteRequestHeaders(req, headers)

Called to rewrite the headers of the request, before them being sent to the downstream server. It must return the new headers object.


Called to rewrite the headers of the response, before them being copied over to the outer response. It must return the new headers object.


Extended options supported by http[s].request method ( The following options are dynamically assigned: method, port, path, hostname, headers, agent.

http2 options are limited to timeout only, while undici supports none.


Replaces the original querystring of the request with what is specified. This will get passed to querystring.stringify.

Related topics

  • http-agent:
  • https-agent:


Special thanks to fastify-reply-from developers for creating a production ready library from where we could initially fork.



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free