Skip to content

[Replacement]: mz, thenify and thenify-all #1310

Backlog

Description

@maksimgm

Package to replace

mz, thenify, thenify-all

Package link

https://npmx.dev/package/mz
https://npmx.dev/package/thenify
https://npmx.dev/package/thenify-all

Native replacement(s)

util.promisify, fs.promises (both already in the native manifest), plus node:dns/promises and node:readline/promises

Documentation

https://nodejs.org/api/util.html#utilpromisifyoriginal
https://nodejs.org/api/fs.html#promises-api

Availability

Node.js v8+ for util.promisify, v10+ for fs.promises, Deno and Bun via node:

Rationale

mz wraps node's core modules (fs, child_process, crypto, dns, readline, zlib) with thenify-all, which wraps every method with thenify. ~72M weekly downloads each, most of it through sucrase. same idea as es6-promisify and pify, which are already mapped to util.promisify. one difference: thenify resolves an array when the callback gets more than one value, while util.promisify resolves only the first one unless the function has a custom promisify (like child_process.exec, which resolves { stdout, stderr })

Code example (optional)

import fs from 'mz/fs' // [!code --]
import fs from 'node:fs/promises' // [!code ++]

const text = await fs.readFile('file.txt', 'utf8')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions