Node.js HTTP Proxy Tutorial: Send HTTPS Requests with Rola IP and Verify the Exit IP
Nov 30, 2026 · Guides · 14 min read
TL;DR
When one Node.js program needs a proxy, choose a Rola IP network, copy the HTTP connection parameters from the dashboard, and run the client.mjs below. When several local programs need to use the same upstream configuration, run local-proxy.mjs, which listens on 127.0.0.1. First compare the exit IP of your current network with that of the proxied request, then use an authorized business URL to check the actual response. Every CONNECT tunnel sets up its own upstream connection.
What Environment and Parameters Does a Node.js HTTP Proxy Need?
The examples in this article use macOS 14.6, Node.js 24.14.0, npm 11.9.0, Axios 1.21.1, and https-proxy-agent 7.0.6. The terminal figures later in the article record the November 19, 2026 checks of a local mock proxy and of local CONNECT functionality; after you configure your own Rola IP parameters, verify the actual exit and the business response with the commands. The implementation follows the Node.js HTTP CONNECT event documentation, the https-proxy-agent project, and the Axios request configuration.
Create an empty directory and save the following as package.json:
{
"name": "rola-node-http-proxy-guide",
"private": true,
"type": "module",
"dependencies": {
"axios": "1.21.1",
"https-proxy-agent": "7.0.6"
}
}
Install the dependencies and check the versions:
npm install
node --version
npm ls axios https-proxy-agent --depth=0
The verification steps also use curl. OpenSSL is needed only if you enable the optional local HTTPS listener. The environment variable commands below work in zsh or Bash; PowerShell uses a different syntax for variables.
How to Get the HTTP Proxy Connection Details in the Rola IP Dashboard
Open the proxy setup page of the Rola IP network you chose, and copy the HTTP gateway HOST, HTTP PORT, full username, and password. Don’t put a SOCKS5 port into the HTTP proxy code in this tutorial. The Rola IP English Quick Start shows where the fields are; the actual connection values are subject to your own dashboard.

Figure 1. Finding the gateway HOST and PORT in the Rola IP dashboard.
| Environment variable | What to enter | Purpose |
|---|---|---|
PROXY_HOST |
The gateway hostname, without http:// |
Connect to the upstream gateway |
PROXY_PORT |
The HTTP proxy port, in the range 1–65535 | Connect to the upstream gateway |
PROXY_USER |
The full username generated by the dashboard | Authentication and the selected session parameters |
PROXY_PASS |
The proxy password | Authentication |
Set the variables in the terminal where you are about to run Node.js. Don’t write real passwords into source code or public screenshots.
export PROXY_HOST='<your-Rola-HTTP-host>'
export PROXY_PORT='<your-Rola-HTTP-port>'
export PROXY_USER='<your-generated-username>'
export PROXY_PASS='<your-proxy-password>'
For residential proxies, the region or session options may be reflected in the username generated by the dashboard, so copy it in full and don’t edit it yourself. When you need to keep the same session continuously, you can choose a suitable fixed-session setting; independent regional checks can use a rotating configuration. Specific parameters are subject to the Rola IP English residential proxy documentation and the current dashboard.
How to Send a Node.js HTTP Proxy Request with Rola IP
Save the full program below as client.mjs. It uses the URL API to write the authentication details, so characters such as @ and : in the password are encoded correctly. httpsAgent handles the proxy connection for HTTPS targets, and proxy: false stops Axios from applying another layer of proxy settings. Because this example does not set httpAgent, the code explicitly rejects http:// targets.
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const { PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS } = process.env;
const port = Number(PROXY_PORT);
if (!PROXY_HOST || !Number.isInteger(port) || port < 1 || port > 65535 || !PROXY_USER || !PROXY_PASS) {
throw new Error('Set valid PROXY_HOST, PROXY_PORT, PROXY_USER and PROXY_PASS');
}
const target = new URL(process.env.CHECK_URL ?? 'https://api.ipify.org?format=json');
if (target.protocol !== 'https:') {
throw new Error('CHECK_URL must use https:; this example only configures httpsAgent');
}
const proxy = new URL(`http://${PROXY_HOST}:${port}`);
proxy.username = PROXY_USER;
proxy.password = PROXY_PASS;
try {
const start = Date.now();
const response = await axios.get(target.href, {
httpsAgent: new HttpsProxyAgent(proxy),
proxy: false,
timeout: 15000,
maxRedirects: 0,
});
console.log(JSON.stringify({ status: response.status, elapsedMs: Date.now() - start, data: response.data }));
} catch (error) {
console.error(JSON.stringify({
status: error.response?.status ?? null,
code: error.code ?? 'UNKNOWN',
location: error.response?.headers?.location ?? null,
retryAfter: error.response?.headers?.['retry-after'] ?? null,
data: error.response?.data ?? null,
}));
process.exitCode = 1;
}
Check the syntax first, then send the default exit IP query:
node --check client.mjs
node client.mjs
Normal output contains status, elapsedMs, and data.ip. Check whether data.ip matches the route and region you selected in the Rola IP dashboard, then use an authorized business URL to check the actual response. elapsedMs only shows how long that one request took, so you can’t judge route performance from a single result; the exit IP will also vary with your account, network, region, and session settings.
To check an actual application address, set CHECK_URL to an authorized HTTPS URL:
CHECK_URL='https://your-authorized-host.example/path' node client.mjs
By default, Axios passes non-2xx statuses to catch; the program prints the HTTP status it actually received and sets a non-zero exit code. A transport failure may only have an error code and no HTTP status. maxRedirects: 0 keeps 3xx responses, and the location field in the error output gives the redirect address so you can check whether it belongs to an authorized target. On a 429, retryAfter in the output keeps the wait time or HTTP date given by the server; the code does not retry automatically, so wait until the permitted time before sending the request again.
How to Create a Node.js HTTP Proxy Server for Local Programs
You only need to run the local service in this section when several local programs have to share one upstream configuration, or when you need to observe the CONNECT process. Save the full code as local-proxy.mjs. It listens only on 127.0.0.1, accepts HTTPS CONNECT requests aimed at port 443, and forwards them to Rola IP. Ordinary HTTP requests receive a 405. This program is a local configuration and debugging tool, not a multi-user proxy service open to the public internet.
import http from 'node:http';
import https from 'node:https';
import { Buffer } from 'node:buffer';
import { readFileSync } from 'node:fs';
const { PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS } = process.env;
const upstreamPort = Number(PROXY_PORT);
const localPort = Number(process.env.LOCAL_PROXY_PORT ?? 8080);
const handshakeMs = Number(process.env.CONNECT_TIMEOUT_MS ?? 15000);
const idleMs = Number(process.env.TUNNEL_IDLE_MS ?? 60000);
const validPort = (port) => Number.isInteger(port) && port >= 1 && port <= 65535;
const validTimeout = (value) => Number.isInteger(value) && value >= 1 && value <= 600000;
if (!PROXY_HOST || !validPort(upstreamPort) || !PROXY_USER || !PROXY_PASS || !validPort(localPort)
|| !validTimeout(handshakeMs) || !validTimeout(idleMs)) {
throw new Error('Set valid upstream credentials, ports (1-65535), and timeouts (1-600000 ms)');
}
const tlsKey = process.env.LOCAL_PROXY_TLS_KEY;
const tlsCert = process.env.LOCAL_PROXY_TLS_CERT;
if (Boolean(tlsKey) !== Boolean(tlsCert)) {
throw new Error('Set both LOCAL_PROXY_TLS_KEY and LOCAL_PROXY_TLS_CERT');
}
const rejectPlainHttp = (_request, response) => {
response.writeHead(405, { Allow: 'CONNECT' });
response.end('This listener only supports HTTPS CONNECT tunnels.');
};
const server = tlsKey
? https.createServer({ key: readFileSync(tlsKey), cert: readFileSync(tlsCert) }, rejectPlainHttp)
: http.createServer(rejectPlainHttp);
const auth = `Basic ${Buffer.from(`${PROXY_USER}:${PROXY_PASS}`).toString('base64')}`;
server.on('connect', (request, client, clientHead) => {
const authority = request.url ?? '';
if (!/^[A-Za-z0-9.-]+:443$/.test(authority)) {
client.end('HTTP/1.1 400 Bad Request\r\n\r\n');
return;
}
let tunnel;
let established = false;
const earlyData = [];
let earlyBytes = 0;
const upstream = http.request({
host: PROXY_HOST,
port: upstreamPort,
method: 'CONNECT',
path: authority,
headers: { 'Proxy-Authorization': auth },
});
const closeBoth = () => {
clearTimeout(handshakeTimer);
upstream.destroy();
tunnel?.destroy();
client.destroy();
};
const fail = (status, phrase) => {
clearTimeout(handshakeTimer);
if (established || client.destroyed) return closeBoth();
client.end(`HTTP/1.1 ${status} ${phrase}\r\n\r\n`);
upstream.destroy();
tunnel?.destroy();
};
const report = (stage, details = {}) => {
console.error(JSON.stringify({ stage, ...details }));
};
const handshakeTimer = setTimeout(() => {
report('upstream_connect_deadline');
fail(504, 'Gateway Timeout');
}, handshakeMs);
client.on('error', closeBoth);
const bufferEarlyData = (chunk) => {
earlyBytes += chunk.length;
if (earlyBytes > 65536) return fail(400, 'Bad Request');
earlyData.push(chunk);
};
client.on('data', bufferEarlyData);
client.on('end', closeBoth);
client.on('close', () => { clearTimeout(handshakeTimer); upstream.destroy(); tunnel?.destroy(); });
upstream.on('error', (error) => {
report('upstream_tcp', { code: error.code ?? 'UNKNOWN' });
fail(502, 'Bad Gateway');
});
upstream.on('response', (response) => {
report('upstream_http', { status: response.statusCode });
fail(response.statusCode === 407 ? 407 : 502,
response.statusCode === 407 ? 'Proxy Authentication Required' : 'Bad Gateway');
});
upstream.on('connect', (response, socket, upstreamHead) => {
tunnel = socket;
if (response.statusCode !== 200) {
report('upstream_connect', { status: response.statusCode });
fail(response.statusCode === 407 ? 407 : 502,
response.statusCode === 407 ? 'Proxy Authentication Required' : 'Bad Gateway');
return;
}
clearTimeout(handshakeTimer);
established = true;
tunnel.setTimeout(idleMs, closeBoth);
client.setTimeout(idleMs, closeBoth);
tunnel.on('error', closeBoth);
tunnel.on('close', () => client.destroy());
client.pause();
client.off('data', bufferEarlyData);
client.write('HTTP/1.1 200 Connection Established\r\n\r\n');
if (upstreamHead.length) client.write(upstreamHead);
if (clientHead.length) tunnel.write(clientHead);
for (const chunk of earlyData) tunnel.write(chunk);
client.pipe(tunnel);
tunnel.pipe(client);
client.resume();
});
upstream.end();
client.resume();
});
server.on('error', (error) => {
console.error(`Local listener failed: ${error.code ?? error.message}`);
process.exitCode = 1;
});
server.listen(localPort, '127.0.0.1', () => {
console.log(`Local CONNECT proxy: ${tlsKey ? 'https' : 'http'}://127.0.0.1:${localPort}`);
});
Check the syntax:
node --check local-proxy.mjs
Option 1: local HTTP listener. In the terminal where the four PROXY_* variables are already set, start the service, then open a second terminal to test:
node local-proxy.mjs
# In a second terminal:
curl --proxy http://127.0.0.1:8080 \
'https://api.ipify.org?format=json'
The second terminal should receive JSON containing an ip field; compare it with the output of node client.mjs to confirm that both entry points use the expected proxy exit. Sending an ordinary HTTP request directly to the local listener returns 405, as the code was designed to do. Before switching to the next mode, press Ctrl+C to stop the service.
Option 2: local HTTPS listener. This mode adds TLS between the local client and the local proxy. Generate a certificate for local testing only, and start a new process in a terminal that still has the PROXY_* environment variables:
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout dev-key.pem -out dev-cert.pem -days 1 \
-subj '/CN=localhost' -addext 'subjectAltName=DNS:localhost'
LOCAL_PROXY_TLS_KEY=./dev-key.pem LOCAL_PROXY_TLS_CERT=./dev-cert.pem \
LOCAL_PROXY_PORT=8443 node local-proxy.mjs
# In a second terminal:
curl --proxy https://localhost:8443 --proxy-cacert ./dev-cert.pem \
'https://api.ipify.org?format=json'
Check the ip returned in port 8443 mode and compare it with the result of the HTTP mode. --proxy-cacert is only used to verify the local proxy’s development certificate; the target website’s TLS is verified separately. The local TLS here does not encrypt the upstream CONNECT connection from the local service to the Rola HTTP gateway; an HTTPS target still has its own end-to-end TLS tunnel. Don’t turn off certificate verification to cover up an error.

How to Verify the Exit IP of a Node.js HTTP Proxy
First query the IP of your current network path, then query the proxied request. Of the two local listener commands below, run only the one that matches the mode you started:
curl --noproxy '*' 'https://api.ipify.org?format=json'
node client.mjs
# If the 8080 HTTP listener is running:
curl --proxy http://127.0.0.1:8080 'https://api.ipify.org?format=json'
# If the 8443 HTTPS listener is running instead:
curl --proxy https://localhost:8443 --proxy-cacert ./dev-cert.pem \
'https://api.ipify.org?format=json'
--noproxy '*' makes curl bypass its own proxy settings, but it does not bypass a VPN, system routing, or a transparent gateway. So the first command gives you the baseline IP of the current network path. The proxy response JSON contains only the ip field; if the two differ, that helps confirm the current request went through the proxy. If your business requires a specific country or city, you also need to run a separate geolocation lookup on the returned IP and compare it with the region settings in the Rola dashboard. Different geolocation databases may give different results.

An exit IP check only tells you about the network path of that one query. The next step is still to request your business URL and check its HTTP status, response content, and access permissions.
Which Rola IP Network Should You Choose for a Node.js HTTP Proxy?
When you switch Rola IP networks, client.mjs and local-proxy.mjs need no changes; just copy the HTTP gateway and authentication parameters of the corresponding product again. The basis for choosing is whether the target website accepts that type of address, and the business requirements for session continuity, region, and cost.
| Rola IP option | Suitable tasks | Configuration and verification focus |
|---|---|---|
| Static residential IP | Authorized logins, account sessions, or repeated checks that need a relatively stable exit | Choose the region on the corresponding product page and copy the dedicated HTTP connection details; make several consecutive requests and check whether the exit matches expectations. |
| Rotating residential IP | Independent product or regional checks that need to change exits per session | Choose the region and session method in the dashboard and copy the generated username in full; set the session duration by task granularity. |
| Datacenter IP | The target website allows datacenter traffic, and you want to compare traffic cost or response speed | Use that product’s own HTTP endpoint; compare actual responses and total usage under the same target, concurrency, and time period. |
For example, an authorized product catalog collection can first run a small number of requests on rotating residential and datacenter routes separately, confirm the status codes, field completeness, and cost, and then scale up. For the collected fields and workflow, see the Python product information scraping guide and the Target product data scraping guide. The proxy decides the network exit; it does not decide which fields a business page has.
Configure a Rotating Residential Proxy in the Rola IP Dashboard
Open Global Residential IP → Proxy Setup and choose a country; if you need a finer-grained region, check whether the dashboard offers a state or city. Set the fixed-session duration to the time one continuous task needs, and for independent tasks configure the available rotation option. Then choose User & Pass Auth, the HTTP protocol, and the account you use. The Rola IP English residential proxy documentation shows these controls.

In the Server Information area, enter the HOST, HTTP PORT, full account name, and password into PROXY_HOST, PROXY_PORT, PROXY_USER, and PROXY_PASS respectively. Then run node client.mjs to check the exit IP, and run the business request with the specified CHECK_URL. When you change the region, session, or product route, replace these four settings as a group and repeat the verification. For static residential and datacenter products, copy the connection details from each one’s own dashboard page; don’t assume the rotating residential username format applies to them.
How to Troubleshoot Common Node.js HTTP Proxy Errors
| Symptom | Where it fails | How to handle it |
|---|---|---|
407 Proxy Authentication Required |
Upstream username, password, or account permissions | Copy the full authentication details again and confirm you are using the HTTP port. |
ECONNREFUSED before any HTTP response is received |
The local listener isn’t started or the port doesn’t match | Check whether the service terminal printed Local CONNECT proxy, and confirm that curl’s protocol, host, and port match it. This connection refusal is not an HTTP 502. |
Local 502, log shows stage: upstream_tcp, code: ECONNREFUSED |
The local listener is running, but the TCP connection to the upstream gateway was refused | Recheck PROXY_HOST and PROXY_PORT, and check connectivity from your machine to the gateway. The local program maps this upstream transport failure to 502. |
Local 502, log shows stage: upstream_connect, status: 502 |
The upstream gateway replied to CONNECT, but with status 502 | Check the reachability of the gateway, the selected route, and the target address. The local terminal keeps the upstream status. |
Local 502, log shows stage: upstream_http |
The upstream replied to CONNECT with an ordinary HTTP response | Look at the recorded upstream status and check the gateway settings; apart from 407, the local program maps these uniformly to 502. |
504, timeout, or ECONNABORTED |
CONNECT handshake or Axios request timeout | Check the reachability of the gateway and the target site. An Axios timeout can show up as ECONNABORTED. |
ENOTFOUND or EAI_AGAIN |
DNS resolution | First check the gateway hostname and your local DNS, then judge whether the upstream can’t resolve the target domain. |
403 from the target site |
Target site permissions or access rules | Check account permissions, the requested resource, and the source of the response; changing the proxy IP does not create access authorization. |
429 from the target site |
Request rate limit | Check the retryAfter printed by the code, and wait for the number of seconds or the HTTP date before requesting again; see Axios 429 troubleshooting. |
| TLS certificate error | The certificate of the local proxy or the target site | Check the hostname, validity period, and trust chain; for the local development certificate, use --proxy-cacert. |
3xx |
The code doesn’t follow redirects automatically | Look at the location address in the error output, then decide whether to request the authorized redirect target. |
EADDRINUSE |
The local port is already in use | Close the original listening process or change the port. |
When troubleshooting, keep the local service running and run the following command in a second terminal. CONNECT is the status of the proxy tunnel and TARGET is the status of the HTTPS target; combined with the stage and error code in the service terminal, you can tell local connection, upstream gateway, and target website problems apart.
curl --silent --show-error --noproxy '' --proxy http://127.0.0.1:8080 \
--output /dev/null --write-out 'CONNECT=%{http_connect} TARGET=%{http_code}\n' \
'https://api.ipify.org?format=json'
The example uses an independent timer to limit the total wait of the upstream CONNECT handshake to 15 seconds; once a connection is established, 60 seconds without data activity closes the tunnel. You can adjust them with CONNECT_TIMEOUT_MS and TUNNEL_IDLE_MS respectively. The service listens only on the loopback address and closes both sides of the connection when it disconnects.
Conclusion
A single Node.js application can connect to the Rola IP HTTP gateway directly with HttpsProxyAgent; several local programs can share one configuration through the CONNECT service in this article. When choosing between rotating residential, static residential, and datacenter routes, base the decision on session needs, region requirements, and the target website’s actual responses. After finishing the configuration, compare the exit IP first, then test an authorized business URL; if anything goes wrong, combine the CONNECT status, the target status, and the local logs to locate the problem. When you are ready to start configuring, go to the Rola IP console to sign up or log in and get your connection parameters.