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

# Node.js

> Node.js examples with axios, node-fetch, and got

Replace credentials with your [Dashboard](https://turnoxy.com/dashboard) values.

## axios

```javascript theme={null}
const axios = require('axios');

const response = await axios.get('https://api.ipify.org', {
  proxy: {
    host: 'gate.turnoxy.com',
    port: 1318,
    auth: {
      username: 'sub_xxx',
      password: 'pass'
    }
  }
});

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

### With Parameters

```javascript theme={null}
const axios = require('axios');

// Target US IPs
const response = await axios.get('https://api.ipify.org', {
  proxy: {
    host: 'gate.turnoxy.com',
    port: 1318,
    auth: {
      username: 'sub_xxx-country-US',
      password: 'pass'
    }
  }
});

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

### Sticky Session

```javascript theme={null}
const axios = require('axios');

const client = axios.create({
  proxy: {
    host: 'gate.turnoxy.com',
    port: 1318,
    auth: {
      username: 'sub_xxx-session-order123-ttl-10',
      password: 'pass'
    }
  }
});

// Same IP for all requests
for (let i = 0; i < 3; i++) {
  const response = await client.get('https://api.ipify.org');
  console.log(`Request ${i + 1}: ${response.data}`);
}
```

## node-fetch

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

const agent = new HttpsProxyAgent('http://sub_xxx:pass@gate.turnoxy.com:1318');

const response = await fetch('https://api.ipify.org', { agent });
const text = await response.text();
console.log(text);
```

### With Parameters

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

// Target Germany IPs
const agent = new HttpsProxyAgent('http://sub_xxx-country-DE:pass@gate.turnoxy.com:1318');

const response = await fetch('https://api.ipify.org', { agent });
const text = await response.text();
console.log(text);
```

## got

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

const agent = new HttpsProxyAgent('http://sub_xxx:pass@gate.turnoxy.com:1318');

const response = await got('https://api.ipify.org', {
  agent: { https: agent }
});

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

## undici (Node.js 18+)

```javascript theme={null}
const { ProxyAgent, fetch } = require('undici');

const agent = new ProxyAgent('http://sub_xxx:pass@gate.turnoxy.com:1318');

const response = await fetch('https://api.ipify.org', {
  dispatcher: agent
});

const text = await response.text();
console.log(text);
```

## Playwright

```javascript theme={null}
const { chromium } = require('playwright');

const browser = await chromium.launch({
  proxy: {
    server: 'http://gate.turnoxy.com:1318',
    username: 'sub_xxx-country-US',
    password: 'pass'
  }
});

const page = await browser.newPage();
await page.goto('https://api.ipify.org');
console.log(await page.textContent('body'));
await browser.close();
```

## Puppeteer

```javascript theme={null}
const puppeteer = require('puppeteer');

const browser = await puppeteer.launch({
  args: ['--proxy-server=http://gate.turnoxy.com:1318']
});

const page = await browser.newPage();
await page.authenticate({
  username: 'sub_xxx-country-US',
  password: 'pass'
});

await page.goto('https://api.ipify.org');
console.log(await page.evaluate(() => document.body.textContent));
await browser.close();
```
