> For the complete documentation index, see [llms.txt](https://docs.ipwo.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ipwo.net/kai-fa-zhe-wen-dang/dai-ma-shi-li/node.js.md).

# Node.js

使用 Node.js 可以通过 IPWO 代理发起 API 请求、数据采集与浏览器自动化操作，适用于爬虫、自动化与多账号场景。

***

### 支持的方案

```
Axios
Fetch（node-fetch）
Puppeteer
Playwright
```

***

### 一、Axios

适用于：

* API 请求
* 数据采集
* 服务端调用

***

#### 安装

```bash
npm install axios
```

***

#### HTTP 代理示例

```javascript
const axios = require('axios')

const username = 'username_custom_zone_US'
const password = 'password'

async function main() {

  const response = await axios.get(
    'http://ipinfo.io',
    {
      proxy: {
        protocol: 'http',
        host: 'us.ipwo.net',
        port: 7878,
        auth: {
          username,
          password
        }
      },
      timeout: 30000
    }
  )

  console.log(response.data)
}

main()
```

***

### 二、Fetch（node-fetch）

适用于：

* 轻量 API 请求
* 异步数据获取

***

#### 安装

```bash
npm install node-fetch https-proxy-agent
```

***

#### HTTP 代理示例

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

const username = 'username_custom_zone_us'
const password = 'password'

const proxyUrl =
  `http://${username}:${password}@us.ipwo.net:7878`

const agent = new HttpsProxyAgent(proxyUrl)

async function main() {

  const response = await fetch(
    'http://ipinfo.io',
    {
      method: 'GET',
      agent: agent,
      timeout: 30000
    }
  )

  console.log(await response.text())
}

main()
```

***

### 三、Puppeteer

适用于：

* 浏览器自动化
* 网页采集
* TikTok / Facebook 自动化

***

#### 安装

```bash
npm install puppeteer
```

***

#### 代理示例

```javascript
const puppeteer = require('puppeteer')

async function main() {

  const browser = await puppeteer.launch({

    headless: false,

    args: [
      '--proxy-server=http://us.ipwo.net:7878'
    ]

  })

  const page = await browser.newPage()

  await page.authenticate({
    username: 'username_custom_zone_us',
    password: 'password'
  })

  await page.goto('http://ipinfo.io')

}

main()
```

***

### 四、Playwright

适用于：

* 高级浏览器自动化
* 大规模采集
* 多账号场景

***

#### 安装

```bash
npm install playwright
```

***

#### 代理示例

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

async function main() {

  const browser = await chromium.launch({

    proxy: {
      server: 'http://us.ipwo.net:7878',
      username: 'username_custom_zone_us',
      password: 'password'
    },

    headless: false

  })

  const page = await browser.newPage()

  await page.goto('http://ipinfo.io')

}

main()
```

***

### 五、如何检测代理是否生效？

访问：

```
http://ipinfo.io
```

如果：

* IP 已变化
* 国家地区正确

说明代理已经生效。

***

### 六、常见问题

#### [407 Proxy Authentication Required](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/407-proxy-authentication-required.md)

通常是：

* 用户名错误
* 密码错误
* zone 参数错误

***

#### [Timeout 超时](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/chao-shi-timeout.md)

通常是：

* 网络环境异常
* DNS 问题
* 请求频率过高

***

#### IP 未变化

请检查：

* 是否正确配置代理
* 请求是否真正走代理
* 浏览器是否加载代理参数

***

### 七、推荐开发建议

推荐：

* 使用海外 VPS
* 增加 timeout
* 增加 Retry 重试
* 使用粘性 Session

避免：

* 高频请求
* 多账号共用一个 IP

***

### 八、相关文章

* [cURL](/kai-fa-zhe-wen-dang/dai-ma-shi-li/curl-dai-ma-shi-li.md)
* [Python Requests](/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/requests.md)
* [HTTPX](/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/httpx.md)
* [aiohttp](/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/aiohttp-yi-bu.md)
* [如何检测代理是否生效](/dai-li-jian-ce-yu-yin-si-an-quan/ru-he-jian-ce-dai-li-shi-fou-sheng-xiao.md)
* [API 调用与批量采集](/dai-li-ji-chu-zhi-shi/api-diao-yong-yu-pi-liang-cai-ji.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ipwo.net/kai-fa-zhe-wen-dang/dai-ma-shi-li/node.js.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
