> ## Documentation Index
> Fetch the complete documentation index at: https://developers.soax.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js

> Working Node.js code for SOAX residential and mobile proxies. Copy-paste examples using axios and node-fetch.

These examples use [axios](https://axios-http.com/) with [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent). Replace `YOUR_PACKAGE_KEY` with your actual package key from the [dashboard](https://platform.soax.com).

Install the dependencies:

```bash theme={null}
npm install axios https-proxy-agent
```

## Residential proxies

### Rotating (new IP every request)

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

Each time you run this, you'll get a different IP.

### Session (same IP across requests)

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us-session-node1:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

async function run() {
  for (let i = 0; i < 3; i++) {
    const res = await axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent });
    const data = res.data.data;
    console.log(`Request ${i + 1}: ${data.ip} (${data.city}, ${data.country_code})`);
  }
}

run();
```

All three requests will return the same IP.

### Session with timed rotation

Rotate to a new IP every 5 minutes:

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us-session-job1-rotate-timed_300:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

### Target a specific city and ISP

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us-city-new_york-isp-comcast:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

### Session with error retry and lookalike replacement

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us-session-scrape1-onerror-retry_3-prefer-lookalike:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

## Mobile proxies

Add `network-mob` to the proxy URL. Everything else works the same way.

### Rotating

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://network-mob-country-us:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

### Session

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://network-mob-country-us-session-mobile1:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

async function run() {
  for (let i = 0; i < 3; i++) {
    const res = await axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent });
    const data = res.data.data;
    console.log(`Request ${i + 1}: ${data.ip} (${data.carrier})`);
  }
}

run();
```

### Target a specific carrier

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://network-mob-country-us-isp-t_mobile-session-tm1:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent })
  .then(res => console.log(res.data))
  .catch(err => console.error(err.message));
```

## Multiple concurrent sessions

Run several sessions in parallel with unique session IDs:

```javascript theme={null}
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");

const targets = [
  { session: "target_a", country: "us" },
  { session: "target_b", country: "gb" },
  { session: "target_c", country: "de" },
];

async function fetch(target) {
  const agent = new HttpsProxyAgent(
    `http://country-${target.country}-session-${target.session}:YOUR_PACKAGE_KEY@proxy.soax.com:1337`
  );
  const res = await axios.get("https://checker.soax.com/api/ipinfo", { httpsAgent: agent });
  const data = res.data.data;
  return `${target.session}: ${data.ip} (${data.country_code})`;
}

Promise.all(targets.map(fetch)).then(results => results.forEach(r => console.log(r)));
```

## Using node-fetch

If you prefer node-fetch over axios:

```bash theme={null}
npm install node-fetch https-proxy-agent
```

```javascript theme={null}
const fetch = require("node-fetch");
const { HttpsProxyAgent } = require("https-proxy-agent");

const agent = new HttpsProxyAgent("http://country-us:YOUR_PACKAGE_KEY@proxy.soax.com:1337");

fetch("https://checker.soax.com/api/ipinfo", { agent })
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err.message));
```

## Expected response

All examples return a JSON response from the SOAX checker:

```json theme={null}
{
  "status": true,
  "data": {
    "ip": "185.123.45.67",
    "country_code": "US",
    "country_name": "United States",
    "region": "California",
    "city": "Los Angeles",
    "isp": "Spectrum",
    "carrier": ""
  }
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Python examples" icon="code" href="/examples/python">
    Working Python code for SOAX proxies.
  </Card>

  <Card title="Go examples" icon="code" href="/examples/go">
    Working Go code for SOAX proxies.
  </Card>

  <Card title="Residential proxies" icon="wifi" href="/proxies/residential">
    Full parameter reference.
  </Card>

  <Card title="Error codes" icon="triangle-exclamation" href="/troubleshooting/error-codes">
    What to do when something goes wrong.
  </Card>
</CardGroup>
