Proxy setup in Node.js

Proxies in Node.js with axios and https-proxy-agent: HTTP and SOCKS5, a new IP per request on port 823, sticky sessions, password encoding.

Updated · Prokso editorial team

Connection details
Host
gw.prokso.com
Port
823 HTTP · 824 SOCKS5 — new IP per request · 10000–20000 sticky session, HTTP(S) and SOCKS5
Username and password
in your dashboard, on the plan page

Your dashboard generates ready-made lines in the format you need: choose the country, IP type and protocol.

Key takeaways
  • Host gw.prokso.com, ports 823 (HTTP), 824 (SOCKS5), 10000–20000 (sticky sessions, HTTP or SOCKS5)
  • The username and password are in your dashboard on the plan page
  • Check the IP in the response of the proxied request itself: the My IP page in a browser does not test your script
Proxies in Node.js: a short video guide · 0:35

A step-by-step guide to connecting Prokso proxies in Node.js. It takes a few minutes.

Step 1. Get the proxy details from your dashboard

Open your plan and copy the host gw.prokso.com, port, username and password. Port 823 is HTTP and 824 is SOCKS5 (both give a new IP for every request); ports 10000–20000 keep one IP (sticky session) for up to 120 minutes and work as both HTTP and SOCKS5 (each port is a separate address). Set the country in the username: username__cr.ua.

The “Access” block on the plan page: host, ports, username and password for the proxy line
The “Access” block on the plan page: host, ports, username and password for the proxy line

Step 2. Install the packages

You'll need axios and https-proxy-agent: npm i axios https-proxy-agent.

Step 3. Create a proxy agent

Pass the proxy URL to HttpsProxyAgent and attach it to the request. Keep proxy: false so axios doesn't apply its own settings.

// npm i axios https-proxy-agent
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const agent = new HttpsProxyAgent("http://USERNAME:PASSWORD@gw.prokso.com:823");
const { data } = await axios.get("https://api.ipify.org?format=json", { httpsAgent: agent, proxy: false });
console.log(data);

Save it as check.mjs and run node check.mjs.

Step 4. Switch between modes

Port 823 gives a new IP per request, 10000–20000 a stable IP for a session. For SOCKS5 use the socks-proxy-agent package and port 824 (rotation) or the same sticky 10000–20000 port.

Step 5. Check the script output

Run the example from step 3: axios calls https://api.ipify.org through the proxy agent and logs { ip: '…' }. That's the address the website sees, and it should differ from yours. A 407 error means the username or password is wrong. The My IP page in your browser won't show anything useful here, as the browser goes direct.

Example run: the output shows the proxy IP, not yours. On port 823 every run gets a new address
Example run: the output shows the proxy IP, not yours. On port 823 every run gets a new address

One agent for the whole app

Create the proxy agent once and reuse it in all requests. A new agent for every request opens a new connection to the proxy, and the script runs slower. The most convenient way is to build an axios instance with the settings you need:

import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const agent = new HttpsProxyAgent("http://USERNAME:PASSWORD@gw.prokso.com:823");
// one client for the whole app: proxy, timeout, no built-in axios proxy
const http = axios.create({ httpAgent: agent, httpsAgent: agent, proxy: false, timeout: 30000 });

const { data } = await http.get("https://prokso.com/ip");
console.log(data);

Set the timeout explicitly: by default axios waits for a response forever, and a single hung request will stop the queue.

What the errors mean

  • Response 407. The proxy did not accept the username or password. Check the string and the remaining traffic on your plan.
  • ECONNREFUSED. Nothing is responding on the host and port you entered: there is a typo in the address or the port.
  • ETIMEDOUT or ECONNRESET. The connection dropped or was never established. Retry the request: on port 823 it will go out from a new IP.
  • The request went out from your own IP. Either proxy: false is missing and axios applied its own settings, or the agent was not passed for the right protocol.

Codes 403 and 429 come from the site, not from the proxy. What to do about them is described on the proxy error codes page.

Parallel requests

Promise.all starts all the requests at once. With hundreds of addresses, this overloads both the site and your script. Limit the number of simultaneous requests with a queue: ten to twenty is usually enough, and if you get 429 responses, lower it.

FAQ

Does Node.js read the HTTP_PROXY variables?

The built-in modules do not read them by default. It is more reliable to pass the proxy explicitly through an agent, as in the example.

How do I encode a password with special characters?

Wrap the username and password in <code>encodeURIComponent()</code> when you build the proxy address.

How do I keep one IP for a series of requests?

Replace port 823 with a sticky port from the 10000-20000 range: all requests through it will go out from one IP for as long as the session lasts.