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 🙏

© 2026 – Pkg Stats / Ryan Hefner

get-file-information

v2.0.0

Published

Get comprehensive file info in both browser and Node.js — size, MD5/SHA256, dimensions, MIME type, and more

Readme

get-file-information

🌐 同时在浏览器和 Node.js 中获取全面的文件信息 / Get comprehensive file info in both browser and Node.js

npm version license demo


中文

安装

npm install get-file-information

快速开始

浏览器

import { getFileInfo } from 'get-file-information'

const input = document.querySelector('input[type="file"]')
input.addEventListener('change', async (e) => {
  const file = e.target.files[0]
  const info = await getFileInfo(file)
  console.log(info)
  // {
  //   name: "photo.jpg",
  //   stem: "photo",
  //   extension: ".jpg",
  //   size: 2048576,
  //   sizeFormatted: "1.95 MB",
  //   mimeType: "image/jpeg",
  //   md5: "d41d8cd98f00b204e9800998ecf8427e",
  //   sha256: "e3b0c442...",
  //   lastModifiedFormatted: "2024-11-15 09:30:00",
  //   width: 1920,
  //   height: 1080
  // }
})

Node.js

import { getFileInfo } from 'get-file-information'

const info = await getFileInfo('/path/to/photo.jpg')
console.log(info)
// 浏览器字段 + Node.js 专属:
// { absolutePath, birthtime, atime, mode, isDirectory, isSymlink, ino }

工具函数

import { formatSize, formatTime, getExtension, getStem, getBaseName, inferMimeType } from 'get-file-information'

formatSize(2048576)          // "1.95 MB"
formatTime(1700000000000)    // "2024-11-15 09:30:00"
getExtension('photo.jpg')    // ".jpg"
getStem('photo.jpg')         // "photo"
getBaseName('/a/b/c.txt')    // "c.txt"
inferMimeType('data.json')   // "application/json"

API

getFileInfo(input: File | string) → Promise<FileInfo | NodeFileInfo>

通用字段

| 字段 | 类型 | 说明 | |---|---|---| | name | string | 文件名 | | stem | string | 不含后缀的文件名 | | extension | string | 后缀,如 ".jpg" | | size | number | 文件大小(字节) | | sizeFormatted | string | 可读大小,如 "2.35 MB" | | mimeType | string | MIME 类型,如 "image/jpeg" | | md5 | string | MD5 哈希 | | sha256 | string | SHA-256 哈希 | | lastModified | number | 最后修改时间戳(ms) | | lastModifiedFormatted | string | 格式化时间 | | width? | number | 图片/视频宽度 | | height? | number | 图片/视频高度 | | duration? | number | 视频时长(秒,仅浏览器) |

Node.js 专属字段

| 字段 | 类型 | 说明 | |---|---|---| | absolutePath | string | 绝对路径 | | birthtime | number | 创建时间戳 | | birthtimeFormatted | string | 格式化创建时间 | | atime | number | 最后访问时间戳 | | atimeFormatted | string | 格式化访问时间 | | mode | number | 文件权限 | | isDirectory | boolean | 是否目录 | | isSymlink | boolean | 是否符号链接 | | ino | number | inode 编号 |

兼容性

| 浏览器 | MD5 | SHA-256 | 媒体尺寸 | |---|---|---|---| | Chrome 37+ | ✅ | ✅ | ✅ | | Firefox 34+ | ✅ | ✅ | ✅ | | Safari 11+ | ✅ | ✅ | ✅ | | Edge 79+ | ✅ | ✅ | ✅ |

Node.js 16+


English

Install

npm install get-file-information

Quick Start

Browser

import { getFileInfo } from 'get-file-information'

const input = document.querySelector('input[type="file"]')
input.addEventListener('change', async (e) => {
  const info = await getFileInfo(e.target.files[0])
})

Node.js

import { getFileInfo } from 'get-file-information'

const info = await getFileInfo('/path/to/file.jpg')

Utilities

import {
  formatSize, formatTime, getExtension,
  getStem, getBaseName, inferMimeType
} from 'get-file-information'

API

getFileInfo(input: File | string) → Promise<FileInfo | NodeFileInfo>

  • Browser: pass a File object → returns FileInfo
  • Node.js: pass a path string → returns NodeFileInfo (with absolutePath, birthtime, atime, etc.)

See the Chinese section above for the full field table.

Browser Support

| Browser | Md5 | SHA-256 | Dimensions | |---|---|---|---| | Chrome 37+ | ✅ | ✅ | ✅ | | Firefox 34+ | ✅ | ✅ | ✅ | | Safari 11+ | ✅ | ✅ | ✅ | | Edge 79+ | ✅ | ✅ | ✅ |

Node.js 16+


🚀 Live Demo

👉 https://wlxweb.github.io/getFileInfo/

Drag & drop any file to see its full metadata — size, hashes, dimensions, MIME type, and more.


License

ISC © wlxweb