mz

中文文档
2.7.0发布于 2017/09/14MIT近 30 天下载 2.1亿

modernize node.js to current ECMAScript standards

原始使用文档
文档目录7 节
  1. Installation and Usage
  2. Promisification
  3. Promise Engine
  4. FAQ
  5. Can I use this in production?
  6. Will this make my app faster?
  7. Can I add more features?

MZ - Modernize node.js

NPM version Build status Test coverage Dependency Status License Downloads

Modernize node.js to current ECMAScript specifications! node.js will not update their API to ES6+ for a while. This library is a wrapper for various aspects of node.js' API.

Installation and Usage

Set mz as a dependency and install it.

npm i mz

Then prefix the relevant require()s with mz/:

var fs = require('mz/fs')

fs.exists(__filename).then(function (exists) {
  if (exists) // do something
})

With ES2017, this will allow you to use async functions cleanly with node's core API:

const fs = require('mz/fs')


async function doSomething () {
  if (await fs.exists(__filename)) // do something
}

Promisification

Many node methods are converted into promises. Any properties that are deprecated or aren't asynchronous will simply be proxied. The modules wrapped are:

  • child_process
  • crypto
  • dns
  • fs (uses graceful-fs if available)
  • readline
  • zlib
var exec = require('mz/child_process').exec

exec('node --version').then(function (stdout) {
  console.log(stdout)
})

Promise Engine

mz uses any-promise.

FAQ

Can I use this in production?

Yes, Node 4.x ships with stable promises support. For older engines, you should probably install your own promise implementation and register it with require('any-promise/register')('bluebird').

Will this make my app faster?

Nope, probably slower actually.

Can I add more features?

Sure. Open an issue.

Currently, the plans are to eventually support:

  • New APIs in node.js that are not available in older versions of node
  • ECMAScript7 Streams

版本与发布记录

mz 共发布 22 个版本,首次发布于 2014/05/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.7.0latest2017/09/149 年前
2.6.02016/11/229 年前
2.5.02016/11/0410 年前
2.4.02016/03/2410 年前
2.3.12016/02/0210 年前
2.3.02016/01/3110 年前

关于 mz 的常见问题

mz 是什么?

modernize node.js to current ECMAScript standards

如何安装 mz?

在项目目录运行 npm install mz,或使用 pnpm add / yarn add / bun add。

mz 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/mz 是否存在。

mz 可以商用吗?

mz 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

mz 的下载量有多少?

根据 npm 官方下载统计,mz 在 2026/10/05 – 2026/11/03 这 30 天内被下载 211,458,641 次,日均约 7,048,621 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

mz 还在维护吗?

最新版本 2.7.0 发布于 2017/09/14(9 年前);至今共发布 22 个版本,其中过去 12 个月发布了 0 个;首次发布于 2014/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。