Node.js Screenshot API
Server-side screenshot capture with Node.js — for backend services, Express/Fastify APIs, CLI tools, and automation scripts. This guide covers the Node.js screenshot API for server-side use only: streaming responses to disk or S3, Express screenshot middleware, cron jobs, and integrating with Bull/BullMQ for batch processing. Keep API keys on the server where they belong.
Quick Start
Install dependencies
Run npm install node-fetch (for Node.js < 18) or use the built-in fetch API in Node.js 18+.
Get your API key
Sign up for Screenshotly and get your API key from the dashboard.
Copy the code example
Use our Node.js code example as a starting point.
Customize and integrate
Modify the code to fit your specific use case and requirements.
Code Example
// Node.js
const https = require('https');
const fs = require('fs');
const captureScreenshot = async (url, outputPath) => {
const response = await fetch('https://api.screenshotly.app/screenshot', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.SCREENSHOTLY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url,
device: 'desktop',
format: 'png',
}),
});
const buffer = await response.arrayBuffer();
fs.writeFileSync(outputPath, Buffer.from(buffer));
};When to Use Node.js with Screenshotly
Use the Node.js integration for server-side screenshot capture only. Ideal for Express/Fastify backend APIs that generate screenshots on demand, CLI tools, cron jobs, CI/CD pipelines, and batch processing. Choose Node.js when you need to process screenshots in bulk, stream to cloud storage, or run captures as background jobs — all without exposing your API key to the client.
Node.js Best Practices
Use a worker queue (Bull, BullMQ, or Bee-Queue) for server-side batch processing instead of Promise.all() to control concurrency and handle retries.
Stream the API response directly to disk or S3 with pipeline() from 'stream/promises' to avoid buffering large images in memory.
Set an AbortSignal timeout on every fetch call to prevent hung requests from blocking your Node.js event loop.
Store API keys in environment variables and load them with dotenv in development. In production, use AWS Secrets Manager or Vault — never expose keys to the browser.
Want a step-by-step walkthrough?
Read the full Node.js tutorial →API Reference
POST /api/screenshotBearer tokenapplication/jsonFrequently Asked Questions
How do I handle large volumes of screenshots in Node.js?
Use async/await with Promise.all() for parallel processing, but limit concurrency to avoid rate limits. Consider using a queue system like Bull or Agenda for high-volume processing with proper retry logic.
What's the best way to store API keys in Node.js?
Use environment variables with the dotenv package. Never hardcode API keys in your source code. For production, use secure secret management services like AWS Secrets Manager or Azure Key Vault.
Can I use Screenshotly with Express.js APIs?
Absolutely! Create API endpoints that accept URLs and return screenshots. You can stream the response directly to clients or save to cloud storage like AWS S3 for later retrieval.
How do I handle timeouts and retries in Node.js?
Set appropriate timeout values using AbortController or request timeout options. Implement exponential backoff for retries on temporary failures (429, 500, 502, 503 status codes).
Start building with Node.js
Get your API key and start capturing screenshots in minutes.
Other Languages
JavaScript
Capture website screenshots from the browser using client-side JavaScript. Call the Screenshotly API with the Fetch API from React, Vue, Angular, or vanilla JS — no server required for basic workflows. This guide covers browser JavaScript screenshot API usage, async/await patterns, error handling, blob URLs for display, and best practices for CORS and API key security when calling from the client.
Python
Integrate screenshot capture into Python applications using the requests library or httpx. Ideal for data pipelines, Django/Flask web apps, automation scripts, and web scraping projects. Includes examples for synchronous and async requests, saving images to files, and handling rate limits with exponential backoff.
PHP
Add screenshot capabilities to PHP applications using cURL or Guzzle HTTP. Perfect for WordPress plugins, Laravel apps, and REST-based web services. Covers authentication, error handling, saving to local storage or S3, and integrating with Laravel queues for background processing.
Ruby
Screenshot API integration for Ruby and Rails applications using Net::HTTP or the Faraday gem. Streamline visual testing, content generation, and background job processing with Sidekiq. Includes production patterns for retry logic, file uploads to Active Storage, and integration with Rails controller actions.