๐ข
Node.js Usage
Explore server-side adblock detection, API integrations, performance benchmarking, and advanced configuration options for Node.js environments.
๐ Interactive Examples
Basic Detection
import { detectAdblock, type NoBlockyResult } from 'noblocky'; async function basicExample(): Promise<NoBlockyResult> { console.log('๐ Running basic adblock detection...'); try { const result = await detectAdblock(); console.log('โ Detection completed:'); console.log('- Blocked:', result.isBlocked); console.log('- Confidence:', result.confidence); console.log('- Strategies run:', result.strategyResults?.length || 0); console.log('- Timestamp:', new Date(result.timestamp).toISOString()); // Log strategy details result.strategyResults?.forEach((strategy, index) => { console.log(` Strategy ${index + 1}: ${strategy.strategy} (${strategy.confidence})`); }); return result; } catch (error) { console.error('โ Detection failed:', error.message); throw error; } }
๐ Getting Started
1. Installation
npm install noblocky
2. Basic Import
// ES modules import { detectAdblock, NoBlocky } from 'noblocky'; // CommonJS const { detectAdblock, NoBlocky } = require('noblocky');
3. TypeScript Support
import { detectAdblock, NoBlocky, type NoBlockyResult, type NoBlockyOptions } from 'noblocky';
๐ API Reference
detectAdblock(options?)
Quick detection function that returns a Promise with the detection result.
const result = await detectAdblock({ timeout: 5000, debug: true });
NoBlocky Class
Advanced class-based API with caching, callbacks, and configuration management.
const noblocky = new NoBlocky({ timeout: 5000, onDetect: (result) => console.log('Blocked!', result), onNotDetect: (result) => console.log('Clear!', result) }); const result = await noblocky.detect();
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
timeout | number | 5000 | Detection timeout in milliseconds |
debug | boolean | false | Enable debug logging |
onDetect | function | undefined | Callback when adblock is detected |
onNotDetect | function | undefined | Callback when no adblock is detected |
๐ก Common Use Cases
๐ Web Server Integration
Integrate adblock detection into your Express.js or other Node.js web servers.
app.get('/api/adblock-check', async (req, res) => { const result = await detectAdblock(); res.json(result); });
๐ Analytics & Monitoring
Track adblock usage patterns and performance metrics across your application.
const analytics = await performanceBenchmark(); await saveMetrics(analytics);
๐งช Testing & QA
Automated testing of adblock detection across different environments and configurations.
const testResults = await compareMethodsExample(); expect(testResults.every(r => r.result)).toBe(true);
โก Performance Optimization
Benchmark and optimize detection performance for your specific use case.
const cache = await cacheExample(); console.log('Speed boost:', cache.improvement + '%');