# sindresorhus/file-type

Detect the file type of a file, stream, or data

Repository: https://github.com/sindresorhus/file-type
Canonical: https://ross.abutalabs.com/products/file-type
Language: JavaScript
License: MIT
License Family: permissive
Topics: nodejs, javascript, uint8array, buffer, magic-numbers, file, magic, file-types, detect
Last push: 2026-08-15T01:40:38+00:00

## Health v2 (maintenance only)
Score: 98/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 97, release rhythm 98, longevity 100
- inputs: {"age_days": 4514, "days_push": 19, "days_rel": 19, "gap_med": 14, "n_releases_24m": 22}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 4321, forks 394 (observed 2026-08-28T04:08:41.955052+00:00)

## What it is
A Node.js/JavaScript library that detects the file type of a file, stream, or buffer by checking its magic number (binary signature). It returns the detected extension and MIME type for binary-based file formats.

## Use cases
- detect file type from uploaded file in nodejs
- get mime type from a buffer or uint8array
- identify file extension from a stream
- validate uploaded file type by magic numbers
- detect image or video format from file header bytes
- sniff file type of a fetched remote resource

## When to choose
- you need to detect binary file formats in Node.js from files, streams, or buffers
- you want a lightweight, well-maintained ESM package for MIME/extension sniffing
- you need to validate uploads by their actual binary signature rather than filename

## When to avoid
- you need to detect text-based formats like .txt, .csv, or .svg
- you need guaranteed validation that a file is well-formed and not malformed
- your project is CommonJS-only and cannot consume ESM packages

## Facets
- artifact type: library
- maturity: stable
- function: parser, developer-tools, file-system
- domain: developer-tools, files, web-development
- platform: -
- tags: magic-numbers, file-type-detection, mime-type, uint8array, esm, nodejs, javascript

## Member repositories
- sindresorhus/file-type (main) score 98

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:08:41.955052+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T18:21:43.736992+00:00, confidence not recorded.
  - readme: https://github.com/sindresorhus/file-type (fetched 2026-08-28T04:08:41.955052+00:00, sha 6d7ea735dfae)
- Data as of 2026-08-30T08:39:29.467469+00:00.
