In this guide, we’ll walk you through using ZenRows® Residential Proxies with Node.js and Axios. You’ll learn how to integrate the proxies into your requests and troubleshoot common issues. We’ll also address some frequently asked questions about residential proxies.

Installing Axios

First, make sure you have Node.js installed. Then, navigate to your project directory and install Axios using npm by running:

npm install axios

This will install Axios, a popular promise-based HTTP client for Node.js, and add it to your project.

Making Requests with ZenRows Residential Proxies

Follow the steps below to use ZenRows Residential Proxies with Node.js axios library.

1

Get Your Credentials

Navigate to the ZenRows Residential Proxy Generator Page to get your username, password, and proxy domain.

2

Configure the Proxy URL

If necessary, configure your proxy URL on the Generator Page following the guide on Residential Proxies Setup. Your proxy URL should be in this format:

http://<YOUR_USERNAME>:<YOUR_PASSWORD>@superproxy.zenrows.com:1337

Replace <YOUR_USERNAME> and <YOUR_PASSWORD> with your ZenRows proxy credentials.

3

Code Example

Here’s an example of sending a request through ZenRows Residential Proxies to httpbin.io/ip, which returns the IP address used for the request.

scraper.js
const axios = require('axios');

// Proxy credentials
const proxy = {
    protocol: 'http'
    host: 'superproxy.zenrows.com',
    port: '1337',
    auth: {
        username: '<YOUR_USERNAME>',
        password: '<YOUR_PASSWORD>'
    }
};

// Target URL (httpbin returns your IP address)
const targetURL = 'https://httpbin.io/ip';

// Make request using Axios and Residential Proxy
axios({
    method: 'get',
    url: targetURL,
    proxy: proxy
})
.then(response => {
    console.log('Your IP Address:', response.data);
})
.catch(error => {
    console.error('Error:', error.message);
});

Expected output:

Your IP Address: { origin: 'your-residential-proxy-ip' }

Troubleshooting

Here are some common issues you may encounter when using ZenRows Residential Proxies with Node.js axios.

Invalid Proxy Credentials

If you encounter a 407 Proxy Authentication Required or a 401 Unauthorized error, double-check your username and password in the auth section of your proxy configuration. Ensure that they match the credentials in the ZenRows dashboard.

Axios Version

You’re likely to encounter errors if your Axios version is outdated. Ensure you’re using a recent version of Axios that supports your proxy configuration. Older versions may have bugs or lack features for specific proxy setups. To ensure you install the latest version, run the following installation command:

npm install axios@latest

Connection Refused or Blocked

If your requests are being blocked or refused, ensure:

  • You are correctly matching the protocol (http or https) and port (1337 or 1338).
  • The website you’re targeting is not actively blocking you. Some websites employ advanced anti-bot measures that detect proxies.

Invalid Proxy URL Format

Ensure the proxy URL format is correct. It should follow the structure:

http://username:password@proxy-host:port

If any component is missing or incorrectly formatted, the request will fail.

IP Rotation Settings

If you’re not seeing your IP change as expected, check your Sticky TTL settings on ZenRows. If the Sticky TTL is too long, the same IP will be used for multiple requests. Reduce the Sticky TTL to rotate IPs more frequently.

Frequently Asked Questions (FAQs)

For further assistance, feel free to contact us. 😉