mime-db vs mime
MIME Type Handling in Web Development Comparison
1 Year
mime-dbmimeSimilar Packages:
What's MIME Type Handling in Web Development?

In web development, MIME (Multipurpose Internet Mail Extensions) types are crucial for defining the nature and format of files. The 'mime' package is a library for parsing and generating MIME types, while 'mime-db' is a database of all known MIME types and their associated file extensions. Together, they facilitate the correct handling of file types in web applications, ensuring that content is served with the appropriate headers and processed correctly by browsers and clients.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mime-db107,136,3311,164226 kB403 months agoMIT
mime92,179,0112,285108 kB03 months agoMIT
Feature Comparison: mime-db vs mime

Functionality

  • mime-db:

    The 'mime-db' package serves as a static database containing a vast collection of MIME types and their corresponding file extensions. It allows developers to access detailed information about MIME types, including their official definitions and usage.

  • mime:

    The 'mime' package provides functions to get the MIME type of a file based on its extension and to get the extension of a file based on its MIME type. This is essential for serving files correctly in web applications, ensuring that browsers interpret them properly.

Data Size

  • mime-db:

    The 'mime-db' package is significantly larger because it contains a comprehensive list of MIME types. It is best used when the application requires extensive MIME type information, but developers should be mindful of its size.

  • mime:

    The 'mime' package is lightweight, making it suitable for projects where minimizing package size is a priority. It contains only the necessary functionality to handle MIME types without additional overhead.

Update Frequency

  • mime-db:

    The 'mime-db' package is regularly updated to reflect changes in MIME type standards and practices. It is ideal for applications that need to stay current with the latest MIME types.

  • mime:

    The 'mime' package is relatively stable and does not change frequently. It is suitable for projects that do not require constant updates to MIME type handling.

Use Cases

  • mime-db:

    Use the 'mime-db' package in applications that need to validate file uploads against a comprehensive list of MIME types, or when you need to provide detailed MIME type information to users.

  • mime:

    Use the 'mime' package in scenarios where you need to quickly determine the MIME type of files on-the-fly, such as when serving files in a web server or processing uploads.

Integration

  • mime-db:

    The 'mime-db' package can be integrated alongside 'mime' for enhanced functionality, allowing developers to leverage the database for more extensive MIME type information.

  • mime:

    The 'mime' package can be easily integrated into any Node.js application, providing a simple API for MIME type handling without complex setup.

How to Choose: mime-db vs mime
  • mime-db:

    Choose 'mime-db' if you require a comprehensive and up-to-date reference of MIME types and their associated file extensions. It is particularly useful for applications that need to validate or look up MIME types against a wide array of standards.

  • mime:

    Choose 'mime' if you need a lightweight solution for determining the MIME type of files based on their extensions or vice versa. It is ideal for applications where you need to dynamically generate or parse MIME types without the overhead of a larger database.

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.