npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-mime-types

v1.0.4

Published

returns the mime-type, extension and the size of an uploaded file.

Downloads

2

Readme

$ npm install --save file-mime-types

Description

Read on the browser request stream and returns the mime-type, possible extensions and the size of an uploaded file.

When uploading a file from a client, the request should have a "Content-type": "multipart/form-data" header.

Usage Example

html form

// index.html

<form 
    action="/upload" <!-- route -->
    enctype="multipart/form-data" <!-- important -->
    method="POST">
    <input type="file" name="fileUploaded">
    <button type="submit">Upload</button>
 </form>

nodejs server

const http = require('http');
const mimeAndType = require('file-mime-types');
const fs = require('fs');

http.createServer((req, res) => {
  if(req.url === '/upload') {
    req.once('data', (chunk) => {
      console.log(mimeAndType(req, chunk));
    });
  }
  res.setHeader('Content-type', 'text/html');

  fs.readFile(`${__dirname}/index.html`, 'utf8', (err, data) => {
    res.write(data);
    res.end();
  });
  
}).listen(3000);

// examples : 
// { mime: 'text/css', ext: [ 'css' ], byteLength: '72450' }
// { mime: 'application/vnd.debian.binary-package', ext: [ 'deb' ], byteLength: '34493720' }

The ext property of the result is an array of possible extensions.

An empty array means that no extension was found, this may happen if the mime type is application/octet-stream.

The mime-to-ext.json file contains a list of mime-types and the matching file extensions.

{
  "application/atom+xml":"atom",
  "application/json":["json","map","topojson"],
  "application/ld+json":"jsonld",
  "application/rss+xml":"rss",
  "application/vnd.geo+json":"geojson",
  "application/xml":["rdf","xml"],
  "application/javascript":"js",
  "application/manifest+json":"webmanifest",
  "application/x-web-app-manifest+json":"webapp",
  "text/cache-manifest":"appcache",
  "audio/midi":["mid","midi","kar"],
  "audio/mp4":["aac","f4a","f4b","m4a"],
  "audio/mpeg":"mp3",
  "audio/ogg":["oga","ogg","opus"],
  "audio/x-realaudio":"ra",
  "audio/x-wav":"wav",
  "image/bmp":"bmp",
  "image/gif":"gif",
  "image/jpeg":["jpeg","jpg"],
  "image/jxr":["jxr","hdp","wdp"],
  "image/png":"png",
  "image/svg+xml":["svg","svgz"],
  "image/tiff":["tif","tiff"],
  "image/vnd.wap.wbmp":"wbmp",
  "image/webp":"webp",
  "image/x-jng":"jng",
  "video/3gpp":["3gp","3gpp"],
  "video/mp4":["f4p","f4v","m4v","mp4"],
  "video/mpeg":["mpeg","mpg"],
  "video/ogg":"ogv",
  "video/quicktime":"mov",
  "video/webm":"webm",
  "video/x-flv":"flv",
  "video/x-mng":"mng",
  "video/x-ms-asf":["asf","asx"],
  "video/x-ms-wmv":"wmv",
  "video/x-msvideo":"avi",
  "image/x-icon":["cur","ico"],
  "application/msword":"doc",
  "application/vnd.ms-excel":"xls",
  "application/vnd.ms-powerpoint":"ppt",
  "application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx",
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx",
  "application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx",
  "application/vnd.debian.binary-package": "deb",
  "application/font-woff":"woff",
  "application/font-woff2":"woff2",
  "application/vnd.ms-fontobject":"eot",
  "application/x-font-ttf":["ttc", "ttf"],
  "font/opentype":"otf",
  "application/java-archive":["ear","jar","war"],
  "application/mac-binhex40":"hqx",
  "application/octet-stream":["bin","deb","dll","dmg","img","iso","msi","msm","msp","safariextz"],
  "application/pdf":"pdf",
  "application/postscript":["ai","eps","ps"],
  "application/rtf":"rtf",
  "application/vnd.google-earth.kml+xml":"kml",
  "application/vnd.google-earth.kmz":"kmz",
  "application/vnd.wap.wmlc":"wmlc",
  "application/x-7z-compressed":"7z",
  "application/x-bb-appworld":"bbaw",
  "application/x-bittorrent":"torrent",
  "application/x-chrome-extension":"crx",
  "application/x-cocoa":"cco",
  "application/x-java-archive-diff":"jardiff",
  "application/x-java-jnlp-file":"jnlp",
  "application/x-makeself":"run",
  "application/x-cd-image": "iso",
  "application/x-opera-extension":"oex",
  "application/x-perl":["pl","pm"],
  "application/x-pilot":["pdb","prc"],
  "application/x-rar-compressed":"rar",
  "application/x-redhat-package-manager":"rpm",
  "application/x-sea":"sea",
  "application/x-shockwave-flash":"swf",
  "application/x-stuffit":"sit",
  "application/x-tcl":["tcl","tk"],
  "application/x-x509-ca-cert":["crt","der","pem"],
  "application/x-xpinstall":"xpi",
  "application/x-ms-dos-executable":"exe",
  "application/xhtml+xml":"xhtml",
  "application/xslt+xml":"xsl",
  "application/zip":"zip",
  "text/css":"css",
  "text/csv":"csv",
  "text/html":["htm","html","shtml"],
  "text/markdown":"md",
  "text/mathml":"mml",
  "text/plain":"txt",
  "text/vcard":["vcard","vcf"],
  "text/vnd.rim.location.xloc":"xloc",
  "text/vnd.sun.j2me.app-descriptor":"jad",
  "text/vnd.wap.wml":"wml",
  "text/vtt":"vtt",
  "text/x-component":"htc",
  "application/x-desktop": "desktop",
  "text/x-markdown": "md",
  "text/vnd.trolltech.linguist": "ts",
  "image/vnd.microsoft.icon": "ico",
  "application/x-java-archive": "jar",
  "application/x-sharedlib": "so"
}