Node.js client for the Tinify API that intelligently compresses, resizes, converts, and stores images in AVIF, WebP, JPEG, and PNG formats.
—
Configuration settings for the Tinify client including API key authentication, proxy settings, and application identification.
Set your Tinify API key for authentication. This is required before using any image processing functionality.
/**
* Set the API key for authentication with the Tinify API
* @example tinify.key = "your-api-key-here"
*/
let key: string;Usage Example:
const tinify = require("tinify");
// Set API key (required)
tinify.key = "your-api-key-here";
// Now you can use image processing methods
await tinify.fromFile("image.png").toFile("compressed.png");Set an application identifier to be included in the user agent string for API requests.
/**
* Set application identifier for user agent string
* @example tinify.appIdentifier = "MyApp/1.0"
*/
let appIdentifier: string;Usage Example:
const tinify = require("tinify");
tinify.key = "your-api-key";
tinify.appIdentifier = "MyApp/1.0";
// User agent will include: "Tinify/1.8.1 Node/v14.15.0 (linux) MyApp/1.0"Configure proxy settings for API requests when operating behind a corporate proxy.
/**
* Set proxy URL for API requests
* @example tinify.proxy = "http://proxy.example.com:8080"
*/
let proxy: string;Usage Example:
const tinify = require("tinify");
tinify.key = "your-api-key";
tinify.proxy = "http://proxy.example.com:8080";Read-only property that tracks the number of compressions made with your API key this month.
/**
* Current compression count from API headers (read-only)
* Updated automatically after each API request
*/
let compressionCount?: number;Usage Example:
const tinify = require("tinify");
tinify.key = "your-api-key";
await tinify.fromFile("image.png").toFile("compressed.png");
console.log(`Compressions used: ${tinify.compressionCount}`);Validate your API key without performing actual image compression.
/**
* Validate API key without performing compression
* @returns Promise that resolves if key is valid, rejects on error
*/
function validate(): Promise<void>;
/**
* Validate API key with callback support
* @param callback - Callback function receiving error or null
*/
function validate(callback: (err: Error | null) => void): void;Usage Examples:
const tinify = require("tinify");
tinify.key = "your-api-key";
// Promise-based validation
try {
await tinify.validate();
console.log("API key is valid");
} catch (error) {
console.error("Invalid API key:", error.message);
}
// Callback-based validation
tinify.validate((err) => {
if (err) {
console.error("Invalid API key:", err.message);
} else {
console.log("API key is valid");
}
});Configuration methods can throw the following errors:
Install with Tessl CLI
npx tessl i tessl/npm-tinify