All Projects → pd4d10 → promisify-all

pd4d10 / promisify-all

Licence: MIT license
Promisify all Node.js builtin async methods

Programming Languages

javascript
184084 projects - #8 most used programming language

promisify-all Build Status

Promisify all Node.js builtin async methods using util.promisify

Installation

npm install --save promisify-all

Usage

Add the following code to the start of your Node.js project:

const promisifyAll = require('promisify-all')

promisifyAll()

Then you have promisified methods such as fs.readFileAsync and fs.writeFileAsync:

const fs = require('fs')

async function main() {
  try {
    const content = await fs.readFileAsync('/path/to/file', 'utf8')
    console.log('Read file succeed! Content: ', content)

    await fs.writeFileAsync('/path/to/another/file', content)
    console.log('Write file succeed!')
  } catch (err) {
    // Handle errors here
  }
}

main()

Options

suffix

Call promisifyAll as follows to customize suffix. The default suffix is Async.

promisifyAll({
  suffix: 'YourSuffix'
})

Promisified methods list

See here

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].