Localhost HTTP Proxy with Node.js

08 March 2022

Updated: 03 September 2023

An localhost HTTP proxy is useful for debugging and can be easily defined using Node.js by installing http-proxy

Terminal window
1
yarn add http-proxy

And then adding the following to an index.js file:

index.js

1
const httpProxy = require('http-proxy')
2
3
const target = 'http://my-target-website.com:1234'
4
5
httpProxy.createProxyServer({ target }).listen(8080)

Which will create a server that listens on 8080 and will proxy requests to the target