Node.js Logo

Node.js Examples

Ready-to-use Node.js code for integrating CaptchaKings API.

📦 Requirements: Node.js 12+

Installation

bash
npm install captchakings

Quick Start (Recommended)

The easiest way to integrate is using our official Node.js library available on npm.

javascript
const CaptchaKings = require('captchakings');

(async () => {
    // Initialize with your API Key
    const ck = new CaptchaKings('ck_your_api_key_here');
    
    // Solve CAPTCHA
    const result = await ck.solve('/path/to/captcha.jpg');
    
    if (result.success) {
        console.log(`Prediction: ${result.data.prediction}`);
    } else {
        console.log(`Error: ${result.error}`);
    }
})();

Raw Node.js Example

javascript
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

async function solveCaptcha(apiKey, imagePath) {
    const url = 'https://captchakings.com/api/process.php';
    
    const formData = new FormData();
    formData.append('captcha', fs.createReadStream(imagePath));
    
    try {
        const response = await axios.post(url, formData, {
            headers: {
                ...formData.getHeaders(),
                'Authorization': `Bearer ${apiKey}`
            }
        });
        
        return response.data;
    } catch (error) {
        return {
            success: false,
            error: error.message
        };
    }
}

// Usage
(async () => {
    const API_KEY = 'ck_your_api_key_here';
    const IMAGE_PATH = '/path/to/captcha.jpg';
    
    const result = await solveCaptcha(API_KEY, IMAGE_PATH);
    
    if (result.success) {
        console.log(`✅ CAPTCHA Solved: ${result.data.prediction}`);
        console.log(`Confidence: ${result.data.confidence}`);
        console.log(`Credits Remaining: ${result.credits.credits_remaining}`);
    } else {
        console.log(`❌ Error: ${result.error}`);
    }
})();