toolcenter
v1.1.0
Published
Official Node.js SDK for ToolCenter API - Screenshots, PDFs, QR Codes, Website Analysis, and more
Maintainers
Readme
ToolCenter Node.js SDK
Official Node.js SDK for ToolCenter API. Generate screenshots, PDFs, QR codes, extract website metadata, and more with a simple, elegant interface.
Installation
npm install toolcenterQuick Start
import { ToolCenter } from 'toolcenter';
const tc = new ToolCenter('your-api-key');
// Take a screenshot
const screenshot = await tc.screenshot({
url: 'https://example.com',
width: 1920,
format: 'png'
});
// Generate a PDF
const pdf = await tc.pdf({
url: 'https://example.com',
format: 'A4'
});
// Create a QR code
const qr = await tc.qr({
data: 'https://example.com',
size: 300
});
// Extract website metadata
const metadata = await tc.metadata({
url: 'https://example.com'
});
console.log(metadata);Configuration
import { ToolCenter } from 'toolcenter';
// Default configuration
const tc = new ToolCenter('your-api-key');
// Custom base URL
const tc = new ToolCenter('your-api-key', {
baseUrl: 'https://api.toolcenter.dev'
});API Reference
Image & Media
screenshot(options)
Capture a screenshot of any webpage.
const screenshot = await tc.screenshot({
url: 'https://example.com',
width: 1920, // Viewport width
height: 1080, // Viewport height
format: 'png', // png, jpeg, webp
quality: 90, // 1-100 (jpeg/webp only)
fullPage: true, // Capture full page
delay: 1000 // Delay before capture (ms)
});
// Screenshot is a Response object with binary data
const buffer = await screenshot.arrayBuffer();pdf(options)
Generate a PDF from any webpage.
const pdf = await tc.pdf({
url: 'https://example.com',
format: 'A4', // A4, Letter, Legal, etc.
landscape: false, // Orientation
scale: 1, // Scale factor
margin: { // Margin settings
top: '1cm',
bottom: '1cm',
left: '1cm',
right: '1cm'
}
});
// PDF is a Response object with binary data
const buffer = await pdf.arrayBuffer();qr(options)
Generate QR codes.
const qr = await tc.qr({
data: 'https://example.com',
size: 300, // QR code size in pixels
format: 'png', // png, jpeg, svg
errorCorrectionLevel: 'M' // L, M, Q, H
});ogImage(options)
Generate Open Graph images for social media.
const ogImage = await tc.ogImage({
title: 'My Awesome Article',
description: 'This is a great article about...',
image: 'https://example.com/bg.jpg',
theme: 'modern'
});watermark(options)
Add watermarks to images.
const watermarked = await tc.watermark({
image: 'https://example.com/image.jpg',
watermark: 'https://example.com/logo.png',
position: 'bottom-right', // top-left, top-right, bottom-left, bottom-right, center
opacity: 0.5 // 0.0 to 1.0
});compress(options)
Compress and resize images.
const compressed = await tc.compress({
image: 'https://example.com/image.jpg',
quality: 80, // Compression quality 1-100
format: 'jpeg', // Output format
width: 800, // Resize width
height: 600 // Resize height
});htmlToImage(options)
Convert HTML to images.
const image = await tc.htmlToImage({
html: '<div style="color: red;">Hello World!</div>',
width: 1200,
height: 800,
format: 'png'
});placeholder(options)
Generate placeholder images.
const placeholder = await tc.placeholder({
width: 300,
height: 200,
text: '300x200',
background: '#cccccc',
color: '#333333'
});Website Analysis
metadata(options)
Extract comprehensive website metadata.
const metadata = await tc.metadata({
url: 'https://example.com'
});
// Returns: title, description, keywords, og tags, etc.
console.log(metadata.title);
console.log(metadata.description);
console.log(metadata.openGraph);favicon(options)
Get website favicon.
const favicon = await tc.favicon({
url: 'https://example.com',
size: 32
});linkPreview(options)
Generate rich link previews.
const preview = await tc.linkPreview({
url: 'https://example.com'
});
console.log(preview.title);
console.log(preview.description);
console.log(preview.image);techStack(options)
Detect website technology stack.
const techStack = await tc.techStack({
url: 'https://example.com'
});
console.log(techStack.frameworks);
console.log(techStack.cms);
console.log(techStack.analytics);colors(options)
Extract color palette from websites.
const colors = await tc.colors({
url: 'https://example.com',
count: 5
});
console.log(colors.palette);Network & Domain
dns(options)
Perform DNS lookups.
const dns = await tc.dns({
domain: 'example.com',
type: 'A' // A, AAAA, CNAME, MX, TXT, etc.
});
console.log(dns.records);ssl(options)
Check SSL certificate information.
const ssl = await tc.ssl({
domain: 'example.com'
});
console.log(ssl.valid);
console.log(ssl.expiresAt);
console.log(ssl.issuer);status(options)
Check website status and uptime.
const status = await tc.status({
url: 'https://example.com'
});
console.log(status.online);
console.log(status.responseTime);
console.log(status.statusCode);whois(options)
Get WHOIS domain information.
const whois = await tc.whois({
domain: 'example.com'
});
console.log(whois.registrar);
console.log(whois.createdDate);
console.log(whois.expiryDate);Bulk Operations
bulkScreenshot(urls, options)
Screenshot multiple URLs at once.
const results = await tc.bulkScreenshot([
'https://example.com',
'https://google.com',
'https://github.com'
], {
width: 1920,
format: 'png'
});
console.log(results.completed);
console.log(results.failed);bulkPdf(urls, options)
Generate PDFs for multiple URLs.
const results = await tc.bulkPdf([
'https://example.com',
'https://google.com'
], {
format: 'A4'
});bulkMetadata(urls)
Extract metadata from multiple URLs.
const results = await tc.bulkMetadata([
'https://example.com',
'https://google.com',
'https://github.com'
]);
results.forEach(result => {
console.log(result.url, result.title);
});Account
usage()
Get your API usage statistics.
const usage = await tc.usage();
console.log(usage.requests);
console.log(usage.limit);
console.log(usage.remaining);Error Handling
All methods can throw ToolCenterError for API errors:
import { ToolCenter, ToolCenterError } from 'toolcenter';
try {
const screenshot = await tc.screenshot({
url: 'https://example.com'
});
} catch (error) {
if (error instanceof ToolCenterError) {
console.error('API Error:', error.message);
console.error('Status:', error.status);
} else {
console.error('Other Error:', error.message);
}
}Working with Binary Data
For endpoints that return binary data (screenshot, pdf, qr, etc.), you get a Response object:
// Get as ArrayBuffer
const screenshot = await tc.screenshot({ url: 'https://example.com' });
const buffer = await screenshot.arrayBuffer();
// Get as Blob
const blob = await screenshot.blob();
// Save to file (Node.js)
import { writeFile } from 'fs/promises';
const buffer = await screenshot.arrayBuffer();
await writeFile('screenshot.png', Buffer.from(buffer));Requirements
- Node.js 18 or higher
- Valid ToolCenter API key
Links
License
MIT License - see LICENSE file for details.
