After purchasing static IP services from IPNut platform, use the following Node.js code samples for integration.
1. SOCKS5 Proxy Implementation socks5-proxy-demo.js #
/**
* IPNut SOCKS5 Proxy Integration Demo
*/
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';
import http from 'http';
import https from 'https';
class Socks5ProxyDemo {
constructor() {
this.proxyHost = 'proxy.ipnut.com';
this.proxyPort = 28001;
this.proxyUsername = 'ipnut';
this.proxyPassword = '123456789';
// Build SOCKS5 proxy URL
this.proxyUrl = `socks5://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`;
this.socksAgent = new SocksProxyAgent(this.proxyUrl);
console.log('๐ง SOCKS5 Proxy Configuration:', {
host: this.proxyHost,
port: this.proxyPort,
protocol: 'SOCKS5'
});
}
/**
* SOCKS5 Proxy with Axios
*/
async socks5WithAxios() {
console.log('=== SOCKS5 Proxy with Axios ===');
try {
const response = await axios.get('https://httpbin.org/ip', {
httpAgent: this.socksAgent,
httpsAgent: this.socksAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-SOCKS5/1.0',
'Accept': 'application/json'
}
});
console.log('โ
Status Code:', response.status);
console.log('๐ฆ Response Data:', response.data);
return response.data;
} catch (error) {
console.error('โ Request failed:', error.message);
throw error;
}
}
/**
* Multiple requests through SOCKS5 proxy
*/
async socks5MultipleRequests() {
console.log('\n=== SOCKS5 Multiple Requests ===');
const urls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers'
];
const results = [];
for (let i = 0; i < urls.length; i++) {
console.log(`\n๐ Request ${i + 1}: ${urls[i]}`);
try {
const response = await axios.get(urls[i], {
httpAgent: this.socksAgent,
httpsAgent: this.socksAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-Multi/1.0',
'X-Request-ID': `socks5-${i + 1}`
}
});
console.log('โ
Status Code:', response.status);
console.log('๐ Response Preview:',
JSON.stringify(response.data).substring(0, 120) + '...');
results.push({ success: true, data: response.data });
// Rate limiting
await new Promise(resolve => setTimeout(resolve, 1000));
} catch (error) {
console.error('โ Request failed:', error.message);
results.push({ success: false, error: error.message });
}
}
return results;
}
/**
* SOCKS5 Proxy with custom POST request
*/
async socks5CustomRequest() {
console.log('\n=== SOCKS5 Custom POST Request ===');
try {
const postData = {
service: 'IPNut Proxy',
protocol: 'SOCKS5',
timestamp: new Date().toISOString(),
features: ['static_ip', 'high_anonymity', 'enterprise_grade'],
test_id: Math.random().toString(36).substring(7)
};
const response = await axios.post(
'https://httpbin.org/post',
postData,
{
httpAgent: this.socksAgent,
httpsAgent: this.socksAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-POST/1.0',
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Proxy-Type': 'SOCKS5'
}
}
);
console.log('โ
Status Code:', response.status);
console.log('๐จ POST Response Summary:');
console.log(' - Headers Received:', Object.keys(response.data.headers || {}).length);
console.log(' - Data Validated:', !!response.data.json);
console.log(' - Origin IP:', response.data.origin);
return response.data;
} catch (error) {
console.error('โ POST request failed:', error.message);
throw error;
}
}
/**
* SOCKS5 Proxy with native HTTP module
*/
async socks5WithHttpModule() {
console.log('\n=== SOCKS5 with Native HTTP Module ===');
return new Promise((resolve, reject) => {
const options = {
hostname: 'httpbin.org',
port: 80,
path: '/ip',
method: 'GET',
agent: this.socksAgent,
headers: {
'User-Agent': 'IPNut-Node-Native/1.0',
'Accept': 'application/json',
'Connection': 'close'
}
};
const req = http.request(options, (res) => {
let data = '';
console.log('โ
Status Code:', res.statusCode);
console.log('๐ Response Headers:', res.headers);
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('๐ฆ Response Body:', data);
resolve(data);
});
});
req.on('error', (error) => {
console.error('โ Request error:', error.message);
reject(error);
});
req.setTimeout(30000, () => {
req.destroy();
console.error('โ Request timeout');
reject(new Error('Request timeout'));
});
req.end();
});
}
/**
* Advanced SOCKS5 configuration with error handling
*/
async socks5Advanced() {
console.log('\n=== SOCKS5 Advanced Configuration ===');
try {
// Custom agent with additional options
const advancedAgent = new SocksProxyAgent(this.proxyUrl, {
timeout: 30000,
keepAlive: true
});
const response = await axios.get('https://httpbin.org/anything', {
httpAgent: advancedAgent,
httpsAgent: advancedAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Advanced-Client/1.0',
'Accept': 'application/json',
'X-Custom-Header': 'socks5-test',
'X-Client-Version': '1.0.0'
},
params: {
test: 'ipnut_proxy',
timestamp: Date.now()
}
});
console.log('โ
Advanced Request Completed');
console.log('๐ Response Metrics:');
console.log(' - Status Code:', response.status);
console.log(' - Response Size:', JSON.stringify(response.data).length, 'bytes');
console.log(' - Headers Count:', Object.keys(response.data.headers || {}).length);
return response.data;
} catch (error) {
console.error('โ Advanced request failed:', error.message);
throw error;
}
}
/**
* Run all SOCKS5 demonstrations
*/
async runAll() {
console.log('๐ Starting IPNut SOCKS5 Proxy Tests...\n');
try {
await this.socks5WithAxios();
await this.socks5MultipleRequests();
await this.socks5CustomRequest();
await this.socks5WithHttpModule();
await this.socks5Advanced();
console.log('\n๐ All SOCKS5 proxy tests completed successfully!');
} catch (error) {
console.error('\n๐ฅ SOCKS5 tests completed with errors');
}
}
}
// Run SOCKS5 demo if executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
const socks5Demo = new Socks5ProxyDemo();
socks5Demo.runAll().catch(console.error);
}
export { Socks5ProxyDemo };
2. HTTP Proxy Implementation http-proxy-demo.js #
/**
* IPNut HTTP Proxy Integration Demo
*/
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
import http from 'http';
import https from 'https';
class HttpProxyDemo {
constructor() {
this.proxyHost = 'proxy.ipnut.com';
this.proxyPort = 28001;
this.proxyUsername = 'ipnut';
this.proxyPassword = '123456789';
// Build HTTP proxy URL
this.proxyUrl = `http://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`;
this.httpAgent = new HttpsProxyAgent(this.proxyUrl);
console.log('๐ง HTTP Proxy Configuration:', {
host: this.proxyHost,
port: this.proxyPort,
protocol: 'HTTP'
});
}
/**
* HTTP Proxy with Axios
*/
async httpWithAxios() {
console.log('=== HTTP Proxy with Axios ===');
try {
const response = await axios.get('https://httpbin.org/ip', {
httpsAgent: this.httpAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-HTTP/1.0',
'Accept': 'application/json'
}
});
console.log('โ
Status Code:', response.status);
console.log('๐ฆ Response Data:', response.data);
return response.data;
} catch (error) {
console.error('โ Request failed:', error.message);
throw error;
}
}
/**
* HTTP Proxy with concurrent requests
*/
async httpMultipleRequests() {
console.log('\n=== HTTP Proxy Concurrent Requests ===');
const urls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers',
'https://httpbin.org/get?test=ipnut_proxy'
];
const requests = urls.map((url, index) =>
axios.get(url, {
httpsAgent: this.httpAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-Concurrent/1.0',
'X-Request-ID': `http-${index + 1}`
}
}).then(response => {
console.log(`\nโ
Request ${index + 1}: ${url}`);
console.log(' Status Code:', response.status);
console.log(' Data Preview:',
JSON.stringify(response.data).substring(0, 100) + '...');
return { success: true, data: response.data };
}).catch(error => {
console.log(`\nโ Request ${index + 1} failed:`, error.message);
return { success: false, error: error.message };
})
);
const results = await Promise.all(requests);
console.log(`\n๐ Concurrent Requests Summary: ${results.filter(r => r.success).length}/${urls.length} successful`);
return results;
}
/**
* HTTP Proxy POST with JSON data
*/
async httpPostRequest() {
console.log('\n=== HTTP Proxy POST Request ===');
try {
const postData = {
service: 'IPNut HTTP Proxy',
protocol: 'HTTP',
authentication: 'basic_auth',
timestamp: new Date().toISOString(),
test_payload: {
feature: 'static_residential_ip',
performance: 'high_speed',
reliability: 'enterprise_grade'
}
};
const response = await axios.post(
'https://httpbin.org/post',
postData,
{
httpsAgent: this.httpAgent,
timeout: 30000,
headers: {
'User-Agent': 'IPNut-Node-HTTP-POST/1.0',
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-API-Version': '1.0'
}
}
);
console.log('โ
POST Request Completed');
console.log('๐จ Response Details:');
console.log(' - Status Code:', response.status);
console.log(' - Data Validated:', !!response.data.json);
console.log(' - Headers Count:', Object.keys(response.data.headers || {}).length);
console.log(' - Origin IP:', response.data.origin);
return response.data;
} catch (error) {
console.error('โ POST request failed:', error.message);
throw error;
}
}
/**
* HTTP Proxy with native HTTPS module
*/
async httpWithHttpsModule() {
console.log('\n=== HTTP Proxy with Native HTTPS Module ===');
return new Promise((resolve, reject) => {
const options = {
hostname: 'httpbin.org',
port: 443,
path: '/ip',
method: 'GET',
agent: this.httpAgent,
headers: {
'User-Agent': 'IPNut-Node-HTTPS/1.0',
'Accept': 'application/json'
},
rejectUnauthorized: true
};
const req = https.request(options, (res) => {
let data = '';
console.log('โ
Status Code:', res.statusCode);
console.log('๐ Response Headers:', Object.keys(res.headers).length, 'headers received');
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('๐ฆ Response Body:', data);
resolve(data);
});
});
req.on('error', (error) => {
console.error('โ HTTPS request error:', error.message);
reject(error);
});
req.setTimeout(30000, () => {
req.destroy();
console.error('โ HTTPS request timeout');
reject(new Error('Request timeout'));
});
req.end();
});
}
/**
* HTTP Proxy streaming request
*/
async httpStreamRequest() {
console.log('\n=== HTTP Proxy Streaming Request ===');
return new Promise((resolve, reject) => {
const options = {
hostname: 'httpbin.org',
port: 80,
path: '/stream/5',
method: 'GET',
agent: this.httpAgent,
headers: {
'User-Agent': 'IPNut-Node-Stream/1.0',
'Accept': 'application/json'
}
};
let chunkCount = 0;
const req = http.request(options, (res) => {
console.log('โ
Stream Connected - Status Code:', res.statusCode);
res.setEncoding('utf8');
res.on('data', (chunk) => {
chunkCount++;
console.log(`๐ฆ Chunk ${chunkCount}:`, chunk.toString().trim());
});
res.on('end', () => {
console.log(`๐ Stream ended - ${chunkCount} chunks received`);
resolve(chunkCount);
});
});
req.on('error', (error) => {
console.error('โ Stream request error:', error.message);
reject(error);
});
req.end();
});
}
/**
* Run all HTTP demonstrations
*/
async runAll() {
console.log('๐ Starting IPNut HTTP Proxy Tests...\n');
try {
await this.httpWithAxios();
await this.httpMultipleRequests();
await this.httpPostRequest();
await this.httpWithHttpsModule();
await this.httpStreamRequest();
console.log('\n๐ All HTTP proxy tests completed successfully!');
} catch (error) {
console.error('\n๐ฅ HTTP tests completed with errors');
}
}
}
// Run HTTP demo if executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
const httpDemo = new HttpProxyDemo();
httpDemo.runAll().catch(console.error);
}
export { HttpProxyDemo };
3. Connectivity Testing Utility proxy-test-tool.js #
/**
* IPNut Proxy Connectivity Testing Tool
*/
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
class ProxyTestTool {
constructor() {
this.proxyHost = 'proxy.ipnut.com';
this.proxyPort = 28001;
this.proxyUsername = 'ipnut';
this.proxyPassword = '123456789';
}
/**
* Test SOCKS5 proxy connectivity
*/
async testSocks5Proxy() {
console.log('๐ Testing SOCKS5 Proxy Connectivity:');
const proxyUrl = `socks5://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`;
const socksAgent = new SocksProxyAgent(proxyUrl);
try {
const startTime = Date.now();
const response = await axios.get('https://httpbin.org/ip', {
httpAgent: socksAgent,
httpsAgent: socksAgent,
timeout: 15000,
headers: {
'User-Agent': 'IPNut-Connectivity-Test/1.0'
}
});
const responseTime = Date.now() - startTime;
console.log('โ
SOCKS5 Proxy Connection Successful');
console.log(' ๐ Status Code:', response.status);
console.log(' โก Response Time:', responseTime + 'ms');
console.log(' ๐ Assigned IP:', response.data.origin);
console.log(' ๐ Protocol: SOCKS5');
return { success: true, responseTime, data: response.data };
} catch (error) {
console.log('โ SOCKS5 Proxy Connection Failed:', error.message);
return { success: false, error: error.message };
}
}
/**
* Test HTTP proxy connectivity
*/
async testHttpProxy() {
console.log('\n๐ Testing HTTP Proxy Connectivity:');
const proxyUrl = `http://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`;
const httpAgent = new HttpsProxyAgent(proxyUrl);
try {
const startTime = Date.now();
const response = await axios.get('https://httpbin.org/ip', {
httpsAgent: httpAgent,
timeout: 15000,
headers: {
'User-Agent': 'IPNut-Connectivity-Test/1.0'
}
});
const responseTime = Date.now() - startTime;
console.log('โ
HTTP Proxy Connection Successful');
console.log(' ๐ Status Code:', response.status);
console.log(' โก Response Time:', responseTime + 'ms');
console.log(' ๐ Assigned IP:', response.data.origin);
console.log(' ๐ Protocol: HTTP');
return { success: true, responseTime, data: response.data };
} catch (error) {
console.log('โ HTTP Proxy Connection Failed:', error.message);
return { success: false, error: error.message };
}
}
/**
* Comprehensive proxy testing
*/
async comprehensiveTest() {
console.log('\n=== ๐ง Comprehensive Proxy Test ===');
const testUrls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers'
];
const proxyTypes = [
{ name: 'SOCKS5', agent: SocksProxyAgent },
{ name: 'HTTP', agent: HttpsProxyAgent }
];
const results = [];
for (const proxyType of proxyTypes) {
console.log(`\n๐ก Testing ${proxyType.name} Proxy:`);
for (const testUrl of testUrls) {
const proxyUrl = proxyType.name === 'SOCKS5'
? `socks5://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`
: `http://${this.proxyUsername}:${this.proxyPassword}@${this.proxyHost}:${this.proxyPort}`;
const agent = new proxyType.agent(proxyUrl);
try {
const config = proxyType.name === 'SOCKS5'
? { httpAgent: agent, httpsAgent: agent }
: { httpsAgent: agent };
const response = await axios.get(testUrl, {
...config,
timeout: 10000
});
const success = response.status === 200;
console.log(` ${success ? 'โ
' : 'โ'} ${testUrl} - ${success ? 'Success' : `HTTP ${response.status}`}`);
results.push({
protocol: proxyType.name,
url: testUrl,
success,
status: response.status
});
} catch (error) {
console.log(` โ ${testUrl} - Failed: ${error.message}`);
results.push({
protocol: proxyType.name,
url: testUrl,
success: false,
error: error.message
});
}
}
}
// Summary
const successfulTests = results.filter(r => r.success).length;
const totalTests = results.length;
console.log(`\n๐ Test Summary: ${successfulTests}/${totalTests} tests passed`);
return results;
}
/**
* Run all tests
*/
async runTests() {
console.log('๐ Starting IPNut Proxy Connectivity Tests...\n');
await this.testSocks5Proxy();
await this.testHttpProxy();
await this.comprehensiveTest();
console.log('\n๐ All proxy connectivity tests completed!');
}
}
// Run test tool if executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
const testTool = new ProxyTestTool();
testTool.runTests().catch(console.error);
}
export { ProxyTestTool };
4. Main Program Entry Point main.js #
/**
* Main Program - IPNut Proxy Integration Demo
*/
import { Socks5ProxyDemo } from './socks5-proxy-demo.js';
import { HttpProxyDemo } from './http-proxy-demo.js';
import { ProxyTestTool } from './proxy-test-tool.js';
async function main() {
console.log('๐ IPNut Node.js Proxy Integration Demo');
console.log('======================================\n');
// Display configuration
console.log('๐ง Proxy Configuration:');
console.log(' - Host: proxy.ipnut.com');
console.log(' - Port: 28001');
console.log(' - Protocols: SOCKS5, HTTP');
console.log(' - Authentication: Username/Password\n');
// Run connectivity tests first
console.log('๐งช Phase 1: Connectivity Testing');
const testTool = new ProxyTestTool();
await testTool.runTests();
console.log('\n' + '='.repeat(60) + '\n');
// Run SOCKS5 proxy demonstrations
console.log('๐ Phase 2: SOCKS5 Proxy Implementation');
const socks5Demo = new Socks5ProxyDemo();
await socks5Demo.runAll();
console.log('\n' + '='.repeat(60) + '\n');
// Run HTTP proxy demonstrations
console.log('๐ Phase 3: HTTP Proxy Implementation');
const httpDemo = new HttpProxyDemo();
await httpDemo.runAll();
console.log('\n' + '='.repeat(60));
console.log('๐ All IPNut proxy integration demonstrations completed successfully!');
console.log('๐ก Next Steps:');
console.log(' - Replace demo credentials with your actual IPNut proxy details');
console.log(' - Implement error handling for production use');
console.log(' - Add monitoring and logging for connection health');
console.log(' - Consider connection pooling for high-volume applications');
}
// Run main program
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch(console.error);
}
export { main };
5. Project Structure & Setup package.json #
{
"name": "ipnut-node-proxy-demo",
"version": "1.0.0",
"description": "IPNut SOCKS5 and HTTP Proxy Integration Demo",
"main": "main.js",
"type": "module",
"scripts": {
"start": "node main.js",
"socks5": "node socks5-proxy-demo.js",
"http": "node http-proxy-demo.js",
"test": "node proxy-test-tool.js",
"dev": "node --watch main.js"
},
"dependencies": {
"axios": "^1.6.0",
"socks-proxy-agent": "^8.0.2",
"https-proxy-agent": "^7.0.2"
},
"keywords": [
"ipnut",
"proxy",
"socks5",
"http",
"nodejs"
],
"author": "IPNut Integration",
"license": "MIT"
}
6. Execution Commands #
# File structure:
# node-proxy-demo/
# โโโ socks5-proxy-demo.js # SOCKS5 proxy demo
# โโโ http-proxy-demo.js # HTTP proxy demo
# โโโ proxy-test-tool.js # proxy test tool
# โโโ main.js # Main program entry
# โโโ package.json # Dependency configuration
# Navigate to project directory
cd node-proxy-demo
# Install dependencies
npm install
# Run complete demonstration
npm start
# Or run individual components:
npm run socks5 # SOCKS5 proxy only
npm run http # HTTP proxy only
npm run test # Connectivity tests only
# Development mode with file watching
npm run dev
Key Integration Notes:
ES Modules: Uses modern ES module syntax
Error Handling: Comprehensive error handling and logging
Performance: Connection timeouts and concurrent request support
Security: Proper credential management and SSL verification
Monitoring: Response time tracking and success metrics
Best Practices:
Environment Variables: Store credentials in environment variables for production
Connection Pooling: Implement connection reuse for high-throughput applications
Health Checks: Regular connectivity testing for proxy reliability
Error Recovery: Implement retry mechanisms with exponential backoff
Technical Support
For integration assistance or location-specific requirements:
Email:ย Support@ipnut.com
Live Chat: 24/7 real-time support via official website
*All code examples support both HTTP and SOCKS5 protocols with enterprise-grade authentication and security features.*