mime-db vs mime vs mime-types vs file-type vs mime-lookup
Node.js MIME Type Libraries Comparison
1 Year
mime-dbmimemime-typesfile-typemime-lookupSimilar Packages:
What's Node.js MIME Type Libraries?

These libraries are used in web development to handle MIME types, which are essential for identifying the nature and format of files transmitted over the internet. They provide functionalities to determine file types based on file content or extensions, manage MIME type mappings, and facilitate the retrieval of MIME type information. Proper handling of MIME types is crucial for ensuring that files are processed correctly by web servers and applications, enhancing security and user experience.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mime-db71,038,1781,138219 kB448 months agoMIT
mime70,853,3512,228106 kB13 months agoMIT
mime-types63,281,8421,36318.3 kB11-MIT
file-type21,898,4553,898104 kB107 days agoMIT
mime-lookup28,0141-0-MIT
Feature Comparison: mime-db vs mime vs mime-types vs file-type vs mime-lookup

File Type Detection

  • mime-db:

    The 'mime-db' library does not provide detection capabilities itself; rather, it serves as a comprehensive database of MIME types and their mappings. It can be used in conjunction with other libraries to enhance their functionality by providing extensive MIME type information.

  • mime:

    The 'mime' library does not perform content-based detection; instead, it maps file extensions to MIME types. While it is fast and efficient for known extensions, it lacks the capability to validate the actual content of files, which can be a limitation in certain scenarios.

  • mime-types:

    The 'mime-types' library provides a balance between extension-based lookups and content negotiation. While it primarily focuses on mapping extensions to MIME types, it also supports multiple MIME types for a single extension, allowing for more flexible handling.

  • file-type:

    The 'file-type' library excels in detecting file types based on the binary content of files. It analyzes the first few bytes of a file to determine its type, making it highly reliable for validating file uploads and ensuring that the content matches the expected format.

  • mime-lookup:

    The 'mime-lookup' library offers basic file type detection based on extensions but does not analyze file content. It is designed for quick lookups and is suitable for applications that do not require in-depth validation of file types.

Database of MIME Types

  • mime-db:

    The 'mime-db' library is a rich repository of MIME types, providing an extensive list of types and their corresponding file extensions. It is regularly updated and serves as a reliable source for MIME type information.

  • mime:

    The 'mime' library includes a limited set of MIME types, primarily focusing on common file extensions. It is not as extensive as 'mime-db' and may not cover all possible MIME types.

  • mime-types:

    The 'mime-types' library includes a variety of MIME types and is designed to work seamlessly with other libraries. It provides a good balance of coverage and usability for most applications.

  • file-type:

    The 'file-type' library does not maintain a database of MIME types; it focuses solely on detection based on file content. Users must refer to other libraries for comprehensive MIME type information.

  • mime-lookup:

    The 'mime-lookup' library does not maintain its own database; it relies on existing mappings and is designed for quick lookups without the need for extensive data.

Ease of Use

  • mime-db:

    The 'mime-db' library is primarily a data source and may require additional code to utilize effectively. While it is comprehensive, developers need to implement their own logic for using the data in applications.

  • mime:

    The 'mime' library is also very easy to use, with a simple function for retrieving MIME types based on file extensions. It is lightweight and does not require complex configuration, making it ideal for quick implementations.

  • mime-types:

    The 'mime-types' library is user-friendly and provides a clear API for both MIME type lookups and content negotiation. It is designed to be intuitive, making it easy for developers to implement.

  • file-type:

    The 'file-type' library is easy to use, with a simple API that allows developers to quickly implement file type detection in their applications. It requires minimal setup and is straightforward to integrate into existing workflows.

  • mime-lookup:

    The 'mime-lookup' library offers a simple API for looking up MIME types, making it easy to integrate into applications. Its straightforward design allows for quick lookups without additional complexity.

Performance

  • mime-db:

    The 'mime-db' library's performance depends on how it is used. While it provides extensive data, accessing this data may introduce some latency if not implemented efficiently in applications.

  • mime:

    The 'mime' library is highly performant for extension-based lookups, as it utilizes a simple mapping structure that allows for quick retrieval of MIME types without additional processing.

  • mime-types:

    The 'mime-types' library balances performance and functionality, allowing for efficient lookups while supporting more complex features like content negotiation.

  • file-type:

    The 'file-type' library is optimized for performance when detecting file types based on content. However, it may have a slight overhead compared to extension-based lookups due to the need to read file contents.

  • mime-lookup:

    The 'mime-lookup' library is designed for speed, providing quick lookups for MIME types based on extensions. Its performance is generally high due to its lightweight nature.

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

    Choose 'mime-db' if you need a comprehensive database of MIME types and their associated file extensions. This package is useful for applications that require detailed MIME type information, as it provides a large collection of MIME types that can be referenced or used for validation.

  • mime:

    Choose 'mime' if you require a simple and lightweight library for retrieving MIME types based on file extensions. It is straightforward to use and ideal for applications where you want to quickly map file extensions to their corresponding MIME types without additional overhead.

  • mime-types:

    Choose 'mime-types' if you need a robust library that supports both MIME type lookups and content negotiation. It offers additional features such as support for multiple MIME types for a single file extension and is well-suited for applications that require more complex MIME type handling.

  • file-type:

    Choose 'file-type' if you need to detect file types based on the actual content of the files rather than relying solely on file extensions. This is particularly useful for validating uploads and ensuring that the files are of the expected type before processing them.

  • mime-lookup:

    Choose 'mime-lookup' if you want a straightforward way to look up MIME types based on file extensions. It is designed for quick lookups and is suitable for applications that need to perform MIME type resolution without the need for extensive features or dependencies.

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.