Playground Sign in Start free
Ujeebu SDKs

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-sdk
yarn add @ujeebu-org/ujeebu-sdk
pnpm add @ujeebu-org/ujeebu-sdk

Requirements:

  • 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.

UJEEBU_API_KEY=your_api_key_here
import '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);

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.

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.

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,
  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 ScrapeResponse
Ready to build?

Spin up an API key in 60 seconds

Free tier: 5,000 credits, no card, full access to every endpoint on this page.