mime-db vs mime-types vs mime vs content-type vs file-type
NPM Packages for MIME Type Handling Comparison
1 Year
mime-dbmime-typesmimecontent-typefile-typeSimilar Packages:
What's NPM Packages for MIME Type Handling?

These packages are essential for handling MIME types in web development. They provide functionality for parsing, validating, and working with content types and file types, which are crucial for ensuring that web applications correctly interpret and serve various media types. Understanding the differences between these packages helps developers choose the right tool for their specific needs, whether it's for simple content type parsing or comprehensive file type detection.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mime-db84,763,6241,159226 kB322 months agoMIT
mime-types77,193,1051,38122.3 kB13a month agoMIT
mime71,207,9822,247108 kB0a month agoMIT
content-type38,566,10513610.5 kB32 years agoMIT
file-type24,259,3933,968105 kB1114 days agoMIT
Feature Comparison: mime-db vs mime-types vs mime vs content-type vs file-type

Purpose

  • mime-db:

    The 'mime-db' package serves as a complete database of MIME types and their associated file extensions, providing developers with a reliable source of MIME type information that can be easily updated.

  • mime-types:

    The 'mime-types' package offers a robust set of features for managing MIME types, including methods for content negotiation and looking up types, making it suitable for more complex applications.

  • mime:

    The 'mime' package provides a comprehensive set of utilities for working with MIME types, including looking up MIME types based on file extensions and vice versa, making it a versatile choice for web applications.

  • content-type:

    The 'content-type' package is designed for parsing and formatting HTTP content types, making it easy to work with the Content-Type header in requests and responses.

  • file-type:

    The 'file-type' package is focused on detecting the file type of binary data based on its magic number, which is essential for validating file uploads and ensuring correct processing.

Data Source

  • mime-db:

    This package is a comprehensive database that is regularly updated, providing the latest MIME types and ensuring that applications have access to current information.

  • mime-types:

    Similar to 'mime', this package has a built-in list of types but also offers additional utilities for managing MIME types and content negotiation.

  • mime:

    The 'mime' package comes with a built-in list of MIME types but does not dynamically update, relying on its internal data structure for lookups.

  • content-type:

    This package does not rely on external data sources and is lightweight, focusing solely on parsing and formatting content types based on the standard format.

  • file-type:

    'file-type' analyzes binary data directly to determine the file type, making it independent of external databases or predefined lists.

Performance

  • mime-db:

    The performance of 'mime-db' is excellent for lookups due to its comprehensive nature, but it may introduce overhead if used in scenarios requiring frequent updates.

  • mime-types:

    This package balances performance with functionality, providing efficient lookups while also supporting additional features like content negotiation.

  • mime:

    While 'mime' is efficient for lookups, it may not be as fast as specialized packages like 'file-type' for binary detection, as it relies on string matching.

  • content-type:

    The 'content-type' package is lightweight and efficient, making it suitable for applications where performance is critical and only basic content type handling is required.

  • file-type:

    Performance is optimized for quick detection of file types from binary data, making it suitable for real-time applications that require immediate feedback on file uploads.

Ease of Use

  • mime-db:

    While 'mime-db' provides a wealth of information, its usage may require additional understanding of how to integrate it effectively into applications.

  • mime-types:

    The 'mime-types' package has a comprehensive API that may have a steeper learning curve due to its extensive features, but it is well-documented.

  • mime:

    The 'mime' package offers a clear and intuitive API for MIME type lookups, making it accessible for developers of all skill levels.

  • content-type:

    'content-type' is straightforward to use, with a simple API for parsing and formatting content types, making it ideal for developers who need quick integration.

  • file-type:

    The API for 'file-type' is user-friendly, allowing developers to easily detect file types with minimal setup, which is beneficial for rapid development.

Community and Support

  • mime-db:

    Being a data-centric package, 'mime-db' has a dedicated user base focused on maintaining and updating MIME type information, ensuring reliability.

  • mime-types:

    This package benefits from a strong community and extensive documentation, making it a reliable choice for developers seeking support.

  • mime:

    The 'mime' package is widely used and has a large community, making it easy to find tutorials, examples, and support.

  • content-type:

    This package has a small but active community, providing sufficient support for basic use cases and common issues.

  • file-type:

    'file-type' has gained popularity and has a strong community, ensuring that developers can find help and resources easily.

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

    Use 'mime-db' if you need a complete and up-to-date database of MIME types and their associated file extensions. This package is useful for applications that require frequent updates to MIME type information without the need for additional functionality.

  • mime-types:

    Choose 'mime-types' for a more feature-rich solution that includes methods for content negotiation and MIME type lookup. It's suitable for applications that require both MIME type handling and additional utilities for managing content types.

  • mime:

    Select 'mime' if you need a comprehensive library for working with MIME types, including a large set of predefined types and the ability to look up types based on file extensions. It's great for applications that require extensive MIME type support.

  • content-type:

    Choose 'content-type' if you need a lightweight solution for parsing and formatting HTTP content types. It's ideal for applications that require basic content type handling without additional overhead.

  • file-type:

    Opt for 'file-type' when you need to detect the file type of a buffer or stream based on its binary signature. This package is particularly useful for applications that handle file uploads and need to validate the file type before processing.

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.

Note on MIME Type Data and Semver

This package considers the programmatic api as the semver compatibility. This means the MIME type resolution is not considered in the semver bumps. This means that if you want to pin your mime-db data you will need to do it in your application. While this expectation was not set in docs until now, it is how the pacakge operated, so we do not feel this is a breaking change.

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 associated 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.