mime-db vs mime vs mime-types vs content-type vs file-type vs mime-lookup
MIME Type Handling Libraries Comparison
1 Year
mime-dbmimemime-typescontent-typefile-typemime-lookupSimilar Packages:
What's MIME Type Handling Libraries?

These libraries are designed to manage MIME types in web development, allowing developers to easily determine the content type of files and handle them appropriately. They provide functionalities for parsing, validating, and retrieving MIME types based on file extensions or content, which is essential for serving the correct content type in HTTP responses and ensuring proper file handling in applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mime-db71,562,5211,138219 kB458 months agoMIT
mime71,476,3372,227106 kB13 months agoMIT
mime-types63,724,9141,36218.3 kB11-MIT
content-type35,838,30613410.5 kB32 years agoMIT
file-type22,110,4793,895104 kB106 days agoMIT
mime-lookup27,4681-0-MIT
Feature Comparison: mime-db vs mime vs mime-types vs content-type vs file-type vs mime-lookup

MIME Type Detection

  • mime-db:

    The 'mime-db' package offers a comprehensive database of MIME types, allowing developers to access a wide range of MIME type definitions and their associated file extensions.

  • mime:

    The 'mime' library provides a simple way to map file extensions to their corresponding MIME types, making it easy to serve the correct content type in web applications.

  • mime-types:

    The 'mime-types' library provides a robust set of utilities for parsing and formatting MIME types, making it a versatile choice for handling content negotiation in web applications.

  • content-type:

    The 'content-type' library allows you to parse and format MIME types easily, making it straightforward to handle content types in HTTP headers.

  • file-type:

    The 'file-type' library excels in detecting the MIME type of files based on their binary signatures, ensuring accurate identification regardless of file extension.

  • mime-lookup:

    The 'mime-lookup' library provides a fast and efficient way to look up MIME types based on file extensions, making it ideal for applications that require quick resolution of content types.

Database of MIME Types

  • mime-db:

    Contains a large and up-to-date database of MIME types and their extensions, making it a go-to resource for MIME type information.

  • mime:

    Includes a basic set of MIME types but does not provide a comprehensive database.

  • mime-types:

    Includes a wide range of MIME types but does not provide a dedicated database.

  • content-type:

    Does not maintain a database of MIME types; focuses on parsing and formatting.

  • file-type:

    Does not maintain a database; detects MIME types based on file content.

  • mime-lookup:

    Does not maintain a database; relies on existing MIME type definitions for lookups.

Ease of Use

  • mime-db:

    Provides a simple way to access a comprehensive database, but may require additional handling for specific use cases.

  • mime:

    Straightforward API for mapping file extensions to MIME types, making it easy to integrate into applications.

  • mime-types:

    Comprehensive API that may have a steeper learning curve due to its extensive features, but offers great flexibility.

  • content-type:

    Designed for simplicity, making it easy to parse and format MIME types without complex configurations.

  • file-type:

    User-friendly interface for detecting MIME types based on file signatures, requiring minimal setup.

  • mime-lookup:

    Easy to use for quick MIME type lookups based on file extensions, with minimal overhead.

Performance

  • mime-db:

    Performance may vary based on the size of the database; optimized for quick lookups but can be slower if the database is large.

  • mime:

    Performance is adequate for most applications, but may not be as fast as specialized libraries for specific tasks.

  • mime-types:

    Performance is generally good, but the extensive feature set may introduce some overhead compared to simpler libraries.

  • content-type:

    Lightweight and efficient, suitable for applications where performance is critical and only basic MIME type handling is needed.

  • file-type:

    Highly performant for file type detection, as it analyzes file signatures directly, ensuring quick results.

  • mime-lookup:

    Fast lookups for MIME types based on extensions, making it suitable for high-performance applications.

Community and Maintenance

  • mime-db:

    Maintained by the community with regular updates to the database, ensuring access to the latest MIME types.

  • mime:

    Established library with a strong community and regular updates, ensuring it stays relevant and up-to-date.

  • mime-types:

    Well-established with a large community and frequent updates, making it a robust choice for MIME type handling.

  • content-type:

    Well-maintained with a small but active community, suitable for projects that require basic MIME type handling.

  • file-type:

    Actively maintained with a growing community, making it a reliable choice for file type detection.

  • mime-lookup:

    Moderately maintained with a smaller community, but still reliable for quick MIME type lookups.

How to Choose: mime-db vs mime vs mime-types vs content-type vs file-type vs mime-lookup
  • mime-db:

    Use 'mime-db' if you need access to a large database of MIME types and their associated file extensions. This package is useful for applications that require up-to-date MIME type information and want to avoid hardcoding MIME types in their code.

  • mime:

    Opt for 'mime' if you require a comprehensive solution for working with MIME types, including the ability to map file extensions to MIME types and vice versa. It is suitable for applications that need a robust set of MIME type definitions.

  • mime-types:

    Select 'mime-types' if you need a well-established library that provides a wide range of utilities for working with MIME types, including parsing, formatting, and content negotiation. It is suitable for applications that require a comprehensive approach to MIME type handling.

  • content-type:

    Choose 'content-type' if you need a lightweight library focused on parsing and formatting MIME types. It is ideal for applications that require simple content type handling without additional overhead.

  • file-type:

    Select 'file-type' when you need to detect the MIME type of a file based on its binary signature. This is particularly useful for applications that handle file uploads and need to validate file types based on their content rather than just extensions.

  • mime-lookup:

    Choose 'mime-lookup' for a simple and efficient way to look up MIME types based on file extensions. It is a good choice for applications that need quick and straightforward MIME type resolution without the need for extensive features.

README for mime-db

mime-db

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

This is a large database of mime types and information about them. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API. It aggregates data from the following sources:

  • https://www.iana.org/assignments/media-types/media-types.xhtml
  • https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
  • https://hg.nginx.org/nginx/raw-file/default/conf/mime.types

Installation

npm install mime-db

Database Download

If you intend to use this in a web browser, you can conveniently access the JSON file via jsDelivr, a popular CDN (Content Delivery Network). To ensure stability and compatibility, it is advisable to specify a release tag instead of using the 'master' branch. This is because the JSON file's format might change in future updates, and relying on a specific release tag will prevent potential issues arising from these changes.

https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json

Usage

var db = require('mime-db')

// grab data on .js files
var data = db['application/javascript']

Data Structure

The JSON file is a map lookup for lowercased mime types. Each mime type has the following properties:

  • .source - where the mime type is defined. If not set, it's probably a custom media type.
  • .extensions[] - known extensions associated with this mime type.
  • .compressible - whether a file of this type can be gzipped.
  • .charset - the default charset associated with this type, if any.

If unknown, every property could be undefined.

Contributing

The primary way to contribute to this database is by updating the data in one of the upstream sources. The database is updated from the upstreams periodically and will pull in any changes.

Registering Media Types

The best way to get new media types included in this library is to register them with the IANA. The community registration procedure is outlined in RFC 6838 section 5. Types registered with the IANA are automatically pulled into this library.

Direct Inclusion

If that is not possible / feasible, they can be added directly here as a "custom" type. To do this, it is required to have a primary source that definitively lists the media type. If an extension is going to be listed as associateed with this media type, the source must definitively link the media type and extension as well.

To edit the database, only make PRs against src/custom-types.json or src/custom-suffix.json.

The src/custom-types.json file is a JSON object with the MIME type as the keys and the values being an object with the following keys:

  • compressible - leave out if you don't know, otherwise true/false to indicate whether the data represented by the type is typically compressible.
  • extensions - include an array of file extensions that are associated with the type.
  • notes - human-readable notes about the type, typically what the type is.
  • sources - include an array of URLs of where the MIME type and the associated extensions are sourced from. This needs to be a primary source; links to type aggregating sites and Wikipedia are not acceptable.

To update the build, run npm run build.