npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gemini-file-analyzer-ai

v1.0.0

Published

A Node.js library for analyzing and extracting information from files using Google's Gemini API.

Readme

Gemini File Analyzer

A Node.js library for analyzing files using Google's Gemini Pro Vision model. This library provides an easy-to-use interface for analyzing various types of files (images, PDFs, etc.) using Google's powerful Gemini AI model.

🚀 Features

  • 🔍 File analysis using Gemini Pro Vision
  • ⚙️ Configurable analysis options
  • 📝 TypeScript support with full type definitions
  • 🎯 Easy-to-use API with sensible defaults
  • 📊 Metadata tracking for analysis results
  • 🔒 Environment-based API key management
  • 🧩 Modular and extensible architecture

📋 Requirements

  • Node.js >= 22.0.0
  • Google Gemini API Key
  • TypeScript >= 5.3.3 (for TypeScript projects)

📦 Installation

# Using npm
npm install gemini-file-analyzer-ai

# Using yarn
yarn add gemini-file-analyzer-ai

# Using pnpm
pnpm add gemini-file-analyzer-ai

🏗️ Project Structure

src/
├── config/
│   └── defaults.ts      # Default configuration and constants
├── services/
│   └── file-analyzer.ts # Core analysis service implementation
├── types/
│   └── index.ts         # TypeScript type definitions
└── index.ts             # Main library export

💻 Usage

Basic Usage

import GeminiFileAnalyzer from 'gemini-file-analyzer-ai';
import fs from 'fs';

// Initialize with your API key
const analyzer = new GeminiFileAnalyzer('YOUR_API_KEY');

// Read a file
const fileBuffer = fs.readFileSync('path/to/your/file.jpg');

// Analyze a file with default options
const result = await analyzer.analyzeDocument(fileBuffer, {
  systemInstruction: 'Analyze this image and describe its contents',
  fileType: 'image/jpeg'
});

console.log('Analysis Result:', result.text);
console.log('Metadata:', result.metadata);

Advanced Usage with Custom Options

import GeminiFileAnalyzer from 'gemini-file-analyzer-ai';
import { DocumentAnalysisOptions } from 'gemini-file-analyzer-ai/types';
import fs from 'fs';

// Initialize with your API key
const analyzer = new GeminiFileAnalyzer('YOUR_API_KEY');

// Read a file
const fileBuffer = fs.readFileSync('path/to/your/file.pdf');

// Prepare analysis options
const options: DocumentAnalysisOptions = {
  systemInstruction: 'Extract all text and key information from this document',
  fileType: 'application/pdf',
  analyzerOptions: {
    model: 'gemini-2.5-pro-preview-03-25',
    generationConfig: {
      temperature: 0.5,    // Controls randomness (0.0 to 1.0)
      topP: 0.95,          // Controls diversity (0.0 to 1.0)
      topK: 40,            // Controls token selection
      maxOutputTokens: 18192, // Maximum length of the response
    },
  },
};

// Analyze a file
const result = await analyzer.analyzeDocument(fileBuffer, options);
console.log('Analysis Result:', result.text);
console.log('Metadata:', result.metadata);

Using Environment Variables

import GeminiFileAnalyzer from 'gemini-ocr-analyzer';
import 'dotenv/config';

// Initialize using environment variable
const analyzer = new GeminiFileAnalyzer(process.env.GEMINI_API_KEY!);

// Rest of your code...

🔧 Configuration

Environment Variables

Create a .env file in your project root:

GEMINI_API_KEY=your_api_key_here

Default Configuration

The library comes with optimized defaults:

{
  model: 'gemini-2.0-flash-exp',
  generationConfig: {
    temperature: 0.45,    // Balanced between creativity and accuracy
    topP: 0.95,          // High diversity in responses
    topK: 40,            // Moderate token selection
    maxOutputTokens: 18192, // Sufficient for most documents
    responseMimeType: 'application/json',
  },
}

🛠️ Technologies Used

  • Node.js - Runtime environment
  • TypeScript - Type safety and development experience
  • Google Generative AI SDK - Core AI functionality
  • Biome - Code formatting and linting
  • Husky - Git hooks for code quality
  • dotenv - Environment variable management

📚 API Reference

GeminiFileAnalyzer

Constructor

constructor(apiKey: string)

Methods

analyzeDocument
async analyzeDocument(
  file: Buffer,
  options: DocumentAnalysisOptions
): Promise<DocumentAnalysisResult>

Types

DocumentAnalysisOptions

interface DocumentAnalysisOptions {
  systemInstruction: string;  // Instructions for the AI model
  fileType: string;          // MIME type of the file
  analyzerOptions?: Partial<ReaderOptions>; // Optional configuration overrides
}

DocumentAnalysisResult

interface DocumentAnalysisResult {
  text: string;              // The analysis result text
  metadata?: Record<string, unknown>; // Additional information about the analysis
}

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/kevinlupera/gemini-file-analyzer-ai.git

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

📝 License

This project is licensed under the ISC License - see the LICENSE file for details.