SDK NodeJS

The 9Proxy SDK provides a Node.js wrapper (Node-API addon) for managing residential proxy sessions, port forwarding, authentication, and automatic rotation/renewal.

This document describes the Node-API layer only. Each API method is exported from the native addon and can be invoked directly in your Node.js application.

Quick Start

// quick start

const sdk = require('./build/Release/addon.node');
sdk.initialize('nineproxylibs');

function callOrThrow(fn, ...args){
  const rc = fn(...args);
  if (typeof rc === 'number' && rc !== 0){
    throw new Error(sdk.sdkGetLastError?.() || `SDK error rc=${rc}`);
  }
  return rc;
}

Except for forwarded port information, the SDK does not persist settings (API host, SDK path, port ranges, configured ports). Your app must store these and reapply them to the SDK on each startup.

Typical Flow

Start -> Run SDK -> Set settings (API/ports) -> Restore saved data -> [Close Application] -> Shutdown()

Example Implementation

// Example 

const host = "https://g-api-dev.9proxy.com/sdk/v1";
// Run the SDK loop  
sdk.runAsync();  // or use sdk.run()
 
// Enable debug mode
sdk.enableDebug();

// Set the path to store SDK data
sdk.setSaveDataPath("/var/tmp/save");

// Configure API host
sdk.setAPIHost(host);

// Set default query parameter
sdk.setQuery("api-key", "677e2c4517f247bc89dd66a4");

// Start WebSocket event listener 
sdk.startEventListener(8881, "abcd1234", (data)=> {
	console.log("SDK EVENT", data.toString())
});

// Update IP format + range port
// In Node-API: endPort = start + count - 1 = 60003
sdk.updateIpFormatAndPorts("127.0.0.1:%d", 60000, 60003);

// After all settings are applied, restore previous data to keep forwarded list
sdk.restoreData();

// Example: bind a specific port
try {
  const rc = await sdk.quickCreateAtPort(60000, "request_id", "1");
  console.log("Binding Result:", rc);
} catch (e) {
  console.error("Error:", e.message);
}
// Delay 1 second before shutdown
setTimeout(() => {
  sdk.shutdown()
}, 1000);

Last updated

Was this helpful?