file-type

Detects the file type of a file, buffer, or stream by inspecting magic bytes (file header signatures) rather than relying on file extensions. Supports 100+ file types including images, video, audio, documents, archives, and executables. Used in file upload validation, security scanning, and any agent workflow that needs reliable file type detection independent of extension.

Evaluated Mar 06, 2026 (0d ago) v19.x
Homepage ↗ Repo ↗ Developer Tools file-type mime-type detection magic-bytes node browser binary sindresorhus
⚙ Agent Friendliness
68
/ 100
Can an agent use this?
🔒 Security
96
/ 100
Is it safe for agents?
⚡ Reliability
86
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
88
Error Messages
80
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
90
Secret Handling
90

Content-based detection is more secure than extension-based — prevents extension spoofing attacks. Use as part of defense-in-depth for file upload validation alongside AV scanning.

⚡ Reliability

Uptime/SLA
100
Version Stability
82
Breaking Changes
75
Error Recovery
88
AF Security Reliability

Best When

You need reliable file type detection from content (not extension) for validation, security, or routing in agent file processing pipelines.

Avoid When

You only need MIME type by extension — use the mime-types package for extension-to-MIME mapping without binary inspection.

Use Cases

  • Validate file uploads in agent systems by detecting actual file type from content, not the user-supplied file extension
  • Route agent file processing pipelines based on detected content type — detect actual format before choosing the right parser/processor
  • Security scanning of uploaded files to detect mismatched extensions (e.g., .jpg file that is actually an executable)
  • Build format-agnostic agent file ingestion pipelines where input file type is determined by content inspection, not metadata
  • Validate that agent-generated binary outputs are the expected format before sending to downstream consumers

Not For

  • Text file format detection (plain text, Markdown, source code) — magic bytes don't distinguish text formats; use language detection for text
  • Document format parsing — file-type only detects the type, not the content; use format-specific parsers for content extraction
  • Network traffic analysis — file-type works on buffers, not live network streams in the traditional sense

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No authentication — local file analysis library.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

file-type is open source and free.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • file-type 19.x is ESM-only — require('file-type') fails in CommonJS; use dynamic import() or stay on file-type 16.x for CJS compatibility
  • Returns undefined for unknown types (not an error) — always check if (result) before using result.mime or result.ext
  • file-type only reads the first portion of the file for magic bytes — very large files are not fully read; streaming API reads the minimum needed for detection
  • Some file types share magic bytes or have multiple valid signatures — DOCX/XLSX/PPTX are all ZIP files and may be detected as 'application/zip' not the specific Office format
  • Truncated or corrupted files may return undefined or wrong type — add content validation beyond type detection for production agent upload handling
  • Text-based formats (CSV, JSON, XML, HTML) are not detectable via magic bytes — file-type returns undefined for plain text formats; use other detection methods

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for file-type.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-06.

5442
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered