Node.js / TypeScript SDK
The official Ujeebu SDK for Node.js and TypeScript applications. Built with TypeScript, it provides full type safety and a modern Promise-based API.
Installation
npm install @ujeebu-org/ujeebu-sdkyarn add @ujeebu-org/ujeebu-sdkpnpm add @ujeebu-org/ujeebu-sdkRequirements:
- Node.js 14.0.0 or higher
- npm, yarn, or pnpm package manager
Quick Start
import { UjeebuClient } from '@ujeebu-org/ujeebu-sdk';
// Initialize with your API key
const client = new UjeebuClient(process.env.UJEEBU_API_KEY);
// Scrape a website
const response = await client.scrape('https://example.com', {
js: true,
response_type: 'html'
});
console.log(response.data);const { UjeebuClient } = require('@ujeebu-org/ujeebu-sdk');
// Initialize with your API key
const client = new UjeebuClient(process.env.UJEEBU_API_KEY);
// Scrape a website
const response = await client.scrape('https://example.com', {
js: true,
response_type: 'html'
});
console.log(response.data);Authentication
The SDK requires an API key for authentication. Get yours from the Ujeebu Dashboard.
Using Environment Variables (Recommended)
UJEEBU_API_KEY=your_api_key_hereimport 'dotenv/config';
import { UjeebuClient } from '@ujeebu-org/ujeebu-sdk';
const client = new UjeebuClient(process.env.UJEEBU_API_KEY);WARNING — Security
Never hardcode API keys in your source code or commit them to version control.
Core Methods
scrape()
Scrape web pages with various rendering and extraction options.
const response = await client.scrape('https://example.com');
console.log(response.data);const response = await client.scrape('https://example.com', {
js: true,
js_timeout: 5000,
wait_for: '.dynamic-content'
});
console.log(response.data);const response = await client.scrape('https://example.com', {
extract_rules: {
title: 'h1',
articles: {
selector: '.article',
type: 'list',
data: {
headline: 'h2',
author: '.author'
}
}
}
});extract()
Extract clean article content from web pages.
const response = await client.extract('https://example.com/article');
console.log(response.data.article.title);
console.log(response.data.article.author);
console.log(response.data.article.text);
console.log(response.data.article.pub_date);const response = await client.extract('https://example.com/article', {
strip_tags: 'script,style,nav',
images: true
});serp()
Get structured search engine results.
const response = await client.serp({
search: 'artificial intelligence',
search_type: 'search',
lang: 'en',
results_count: 20
});
console.log(response.data.organic_results);
console.log(response.data.knowledge_graph);const response = await client.serp({
search: 'latest technology news',
search_type: 'news',
lang: 'en',
results_count: 10
});
console.log(response.data.news);const response = await client.serp({
search: 'beautiful landscapes',
search_type: 'images',
results_count: 50
});
console.log(response.data.images);preview()
Generate preview cards for URLs (similar to social media link previews).
const response = await client.preview('https://example.com/article');
console.log(response.data.title);
console.log(response.data.description);
console.log(response.data.image);
console.log(response.data.author);
console.log(response.data.site_name);aiScrape()
Extract structured data using AI-powered natural language prompts.
const response = await client.aiScrape(
'https://example.com/product',
'Extract the product name, price, and rating'
);
console.log(response.data.data);const response = await client.aiScrape(
'https://example.com/product',
'Extract product details',
{
schema: {
type: 'object',
properties: {
name: { type: 'string' },
price: { type: 'number' },
rating: { type: 'number' }
},
required: ['name', 'price']
}
}
);
console.log(response.data.data);autoExtract()
Automatically extract structured data from any web page without writing prompts or selectors.
const response = await client.autoExtract('https://example.com/article');
console.log(response.data.page_type);
console.log(response.data.data);const response = await client.autoExtract('https://example.com/article', {
html: existingHtml // Skip fetching if you already have HTML
});
console.log(response.data.data);const response = await client.autoExtract('https://example.com/product', {
proxy_type: 'premium',
auto_proxy: false,
js: true,
scroll_down: true,
wait_for: '.product-details',
wait_for_timeout: 5000,
timeout: 60000,
force_refresh: true,
auto_captcha_solve: true,
provider: 'openai',
model: 'gpt-4o'
});
console.log(response.data.page_type);
console.log(response.data.data);
console.log('Credits used:', response.headers['ujb-credits']);markdown()
Convert web pages to clean, LLM-optimized markdown.
const response = await client.markdown('https://example.com/article');
console.log(response.data.markdown);const response = await client.markdown('https://docs.example.com/guide', {
filter: 'bm25',
query: 'installation instructions'
});
console.log(response.data.markdown);
console.log(response.data.references);const response = await client.markdown('https://example.com/spa-page', {
filter: 'fit',
citations: true,
js: true,
wait: 3000,
wait_for_selector: '.content-loaded',
timeout: 120,
proxy_type: 'premium'
});
console.log(response.data.markdown);
console.log(response.data.fit_markdown);
console.log(response.data.markdown_with_citations);
console.log(response.data.references);
console.log('Credits used:', response.headers['ujb-credits']);Convenience Methods
getPdf()
Generate a PDF of a web page.
import fs from 'fs';
const response = await client.getPdf('https://example.com', {
js: true,
wait_for: 2000
});
// Save to file
fs.writeFileSync('page.pdf', response.data);getScreenshot()
Capture a screenshot of a web page.
import fs from 'fs';
const response = await client.getScreenshot('https://example.com', {
js: true,
screenshot_fullpage: true
});
fs.writeFileSync('screenshot.png', response.data);const response = await client.getScreenshot('https://example.com', {
screenshot_partial: '.hero-section'
});
fs.writeFileSync('hero.png', response.data);getHtml()
Get clean HTML content.
const response = await client.getHtml('https://example.com', {
js: true,
strip_tags: 'script,style'
});
console.log(response.data);Scrape Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url |
string |
Yes | The URL to scrape. | |
js |
boolean |
No | false |
Enable JavaScript rendering. |
response_type |
string |
No | html |
Output format: 'html', 'screenshot', 'pdf', 'raw'. |
json |
boolean |
No | false |
When true, returns a JSON response instead of raw content. |
timeout |
number |
No | 60 |
Maximum number of seconds before request timeout. |
wait_for |
`string | number` | No | null |
wait_for_timeout |
number |
No | null |
Timeout in milliseconds for the wait_for parameter. |
js_timeout |
number |
No | 30000 |
Timeout for JavaScript execution in milliseconds. |
device |
string |
No | desktop |
Device to emulate: 'desktop', 'mobile', or specific device name. |
extract_rules |
object |
No | null |
Rules for structured data extraction using CSS selectors. |
proxy_type |
string |
No | rotating |
Proxy type: 'rotating', 'advanced', 'premium', 'residential', 'mobile', 'custom'. |
proxy_country |
string |
No | US |
Country ISO code when using premium proxy. |
auto_proxy |
boolean |
No | false |
Automatically try different proxies until one succeeds. |
proxy_session |
string |
No | null |
Alphanumeric identifier to route requests through the same proxy instance. |
auto_captcha_solve |
boolean |
No | false |
Enable automatic CAPTCHA detection and solving. |
auto_captcha_solve_timeout |
number |
No | 120000 |
Timeout in milliseconds for CAPTCHA solving. |
AI Scraper Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url |
string |
Yes | The URL to scrape. | |
prompt |
string |
No | Natural language instruction describing what data to extract. Required unless schema is provided. | |
schema |
object |
No | JSON schema defining the expected structure of extracted data. When provided, prompt becomes optional. | |
temperature |
number |
No | 0.0 |
LLM temperature (0.0-1.0). Lower = more deterministic. |
js |
boolean |
No | true |
Enable JavaScript rendering. |
proxy_type |
string |
No | auto |
Proxy type: 'rotating', 'advanced', 'premium', 'residential'. Auto-selects if not specified. |
proxy_country |
string |
No | null |
ISO country code for proxy location. |
timeout |
number |
No | 120 |
Request timeout in seconds. |
wait_for |
`string | number` | No | null |
Markdown Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url |
string |
Yes | The URL to convert to markdown. | |
filter |
string |
No | fit |
Content filter: 'raw' (full page), 'fit' (main content), 'bm25' (relevance-ranked with query). |
query |
string |
No | null |
Search query for BM25 relevance filtering. Required when filter is 'bm25'. |
citations |
boolean |
No | true (GET) / false (POST) |
Include citation references in the markdown output. Default is true for GET requests, false for POST requests. |
js |
boolean |
No | true |
Enable JavaScript rendering for dynamic pages. |
wait |
number |
No | null |
Milliseconds to wait after page load before conversion. |
wait_for_selector |
string |
No | null |
CSS selector to wait for before conversion. |
timeout |
number |
No | 60 |
Request timeout in seconds. |
proxy |
string |
No | null |
Custom proxy URL to use for the request. |
proxy_type |
string |
No | "" (auto_proxy) |
Proxy type: 'rotating', 'advanced', 'premium', 'residential', 'residential_us', 'residential_geo'. If not set, auto_proxy selects the best proxy automatically. |
auto_captcha_solve |
boolean |
No | true |
Enable automatic CAPTCHA detection and solving. |
auto_captcha_solve_timeout |
number |
No | 0 |
Timeout for CAPTCHA solving in milliseconds. |
AutoExtract Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url |
string |
Yes | The URL to extract data from. | |
html |
string |
No | null |
Pre-fetched HTML content. Skips fetching step when provided. |
proxy_type |
string |
No | "" (auto_proxy) |
Proxy type: 'rotating', 'advanced', 'premium', 'residential', 'residential_us', 'residential_geo'. |
auto_proxy |
boolean |
No | true |
Automatic proxy selection for best results. |
js |
boolean |
No | true |
Enable JavaScript rendering. |
scroll_down |
boolean |
No | false |
Scroll down the page before extraction. |
wait_for |
string |
No | null |
CSS selector to wait for before extraction. |
wait_for_timeout |
number |
No | 30000 |
Timeout in milliseconds for the wait_for selector. |
timeout |
number |
No | 120000 |
Overall request timeout in milliseconds. |
force_refresh |
boolean |
No | false |
Force regeneration of extraction rules even if cached. |
auto_captcha_solve |
boolean |
No | true |
Enable automatic CAPTCHA detection and solving. |
auto_captcha_solve_timeout |
number |
No | 0 |
Timeout in milliseconds for CAPTCHA solving. |
provider |
string |
No | null |
LLM provider for rule generation (e.g., 'openai', 'anthropic', 'google'). |
model |
string |
No | null |
LLM model to use for rule generation. |
Error Handling
try {
const response = await client.scrape('https://example.com');
console.log(response.data);
} catch (error) {
if (error.response) {
// API error response
console.error('Status:', error.response.status);
console.error('Message:', error.response.data.message);
} else if (error.request) {
// Network error
console.error('Network error:', error.message);
} else {
// Other error
console.error('Error:', error.message);
}
}TypeScript Types
The SDK exports all TypeScript types for full type safety:
import {
UjeebuClient,
ScrapeParams,
ScrapeResponse,
ExtractResponse,
SerpParams,
SerpResponse,
CardResponse,
AIScrapeParams,
AIScrapeResponse,
AutoExtractParams,
AutoExtractResponse,
MarkdownParams,
MarkdownResponse
} from '@ujeebu-org/ujeebu-sdk';
// All parameters and responses are fully typed
const params: ScrapeParams = {
js: true,
json: true,
extract_rules: {
title: 'h1'
}
};
const response = await client.scrape('https://example.com', params);
// response.data is typed as ScrapeResponseSpin up an API key in 60 seconds
Free tier: 5,000 credits, no card, full access to every endpoint on this page.