# Configure TrueProxies with Node.js

> Configure TrueProxies authentication and sticky sessions with axios, node-fetch, and https-proxy-agent.

Source: https://docs.trueproxies.com/integrations/javascript/

> **Use your own endpoints**
>
> The examples below use placeholders. Copy the connection host, ports, username, and proxy password from the **Username and password** tab of your service in the dashboard. See [How to connect](https://docs.trueproxies.com/proxy-instructions/how-to-connect/#connection-host-and-ports).

## axios

axios’ built-in `proxy` option does not tunnel HTTPS requests through `CONNECT` reliably. Pass an agent instead, and set `proxy: false` so axios does not also apply its own proxy handling or `HTTP_PROXY` from the environment.

```javascript
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';

const agent = new HttpsProxyAgent(
  'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);

const response = await axios.get('https://httpbin.org/ip', {
  httpsAgent: agent,
  proxy: false,
});

console.log(response.data);
```

## node-fetch

```javascript
import fetch from 'node-fetch';
import { HttpsProxyAgent } from 'https-proxy-agent';

const agent = new HttpsProxyAgent(
  'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);

const response = await fetch('https://httpbin.org/ip', { agent });
const data = await response.json();
console.log(data);
```

## Native fetch (Node.js 18+)

```javascript
import { ProxyAgent } from 'undici';

const proxyAgent = new ProxyAgent(
  'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);

const response = await fetch('https://httpbin.org/ip', {
  dispatcher: proxyAgent,
});

const data = await response.json();
console.log(data);
```

## SOCKS5

```javascript
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';

const agent = new SocksProxyAgent(
  'socks5h://your_username:your_password@YOUR_HOST:YOUR_SOCKS_PORT'
);

const response = await axios.get('https://httpbin.org/ip', {
  httpsAgent: agent,
  proxy: false,
});

console.log(response.data);
```

## Residential IPv4 country targeting

Append `-country-XX` to your username:

```javascript
const agent = new HttpsProxyAgent(
  'http://your_username-country-us:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
```

## Residential IPv4 sticky sessions

```javascript
const agent = new HttpsProxyAgent(
  'http://your_username-session-abc123:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
```

## Related guides

- [Connection and username format](https://docs.trueproxies.com/proxy-instructions/how-to-connect/)
- [HTTP CONNECT and SOCKS5](https://docs.trueproxies.com/proxy-instructions/proxy-protocols/)
- [Trusted IPs](https://docs.trueproxies.com/proxy-instructions/trusted-ips/)
- [Troubleshooting checklist](https://docs.trueproxies.com/support/)
