thordata-js-sdk
v1.3.0
Published
Official JavaScript/TypeScript SDK for Thordata (SERP, Universal, Web Scraper).
Downloads
83
Maintainers
Readme
Thordata Node.js SDK
The Official Node.js/TypeScript Client for Thordata APIs
Proxy Network • SERP API • Web Unlocker • Web Scraper API
📖 Introduction
A fully typed TypeScript SDK for Thordata, optimized for Node.js environments. It provides seamless integration with Thordata's proxy network and scraping APIs.
Key Features:
- 🔒 Type-Safe: Written in TypeScript with complete definitions.
- 🌐 Modern: Uses
axiosand standardhttps-proxy-agentfor reliable connectivity. - ⚡ Lazy Validation: Zero-config initialization; only provide credentials for the features you use.
- 🛡️ Proxy Support: Full support for HTTPS and SOCKS5h protocols with authentication.
📦 Installation
npm install thordata-js-sdk
# or
yarn add thordata-js-sdk🔐 Configuration
We recommend using dotenv to manage credentials.
# .env file
THORDATA_SCRAPER_TOKEN=your_token
THORDATA_RESIDENTIAL_USERNAME=your_username
THORDATA_RESIDENTIAL_PASSWORD=your_password
THORDATA_PROXY_HOST=vpnXXXX.pr.thordata.net🚀 Quick Start
1. SERP Search
import { ThordataClient, Engine } from "thordata-js-sdk";
const client = new ThordataClient({}); // Auto-loads from env
async function search() {
const result = await client.serpSearch({
query: "SpaceX launch",
engine: Engine.GOOGLE_NEWS,
country: "us",
num: 5
});
console.log(result.news_results);
}
search();2. Universal Scrape (Web Unlocker)
async function scrape() {
const html = await client.universalScrape({
url: "https://www.g2.com/products/thordata",
jsRender: true,
waitFor: ".reviews-list",
country: "us"
});
console.log("Page HTML length:", html.length);
}3. Using the Proxy Network
import { Thordata } from "thordata-js-sdk";
// Create a targeted proxy config
const proxy = Thordata.Proxy.residentialFromEnv()
.country("gb")
.city("london")
.sticky(10); // 10 minutes session
const client = new Thordata();
// Request uses the proxy automatically
const response = await client.request("https://ipinfo.io/json", { proxy });
console.log(response);⚙️ Advanced Usage
Task Management (Async)
// Create a scraping task
const taskId = await client.createScraperTask({
fileName: "task_001",
spiderId: "universal",
spiderName: "universal",
parameters: { url: "https://example.com" }
});
console.log(`Task ${taskId} created. Waiting...`);
// Poll for completion
const status = await client.waitForTask(taskId);
if (status === "ready") {
const downloadUrl = await client.getTaskResult(taskId);
console.log("Result:", downloadUrl);
}📄 License
MIT License.
