You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

thenify-all

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thenify-all

Promisifies all the selected functions in an object

1.6.0
latest
Source
npmnpm
Version published
Weekly downloads
20M
0.02%
Maintainers
3
Weekly downloads
 
Created

What is thenify-all?

The thenify-all npm package is used to promisify entire modules or specific sets of functions. This means it can convert callback-based functions or methods to return promises instead, allowing for more modern, cleaner asynchronous code using promises or async/await syntax.

What are thenify-all's main functionalities?

Promisifying an entire module

This code sample demonstrates how to promisify all methods of the Node.js 'fs' module. After promisifying, methods like 'readFile' return a promise that can be used with '.then()' and '.catch()' for handling asynchronous operations.

const thenifyAll = require('thenify-all');
const fs = thenifyAll(require('fs'));

fs.readFile('file.txt', 'utf8').then(contents => {
  console.log(contents);
}).catch(error => {
  console.log(error);
});

Promisifying selected functions

This code sample shows how to promisify only selected functions from the 'fs' module. In this case, only 'readFile' and 'writeFile' are promisified, and they can be used with promise syntax.

const thenifyAll = require('thenify-all');
const fs = require('fs');
const promisifiedFs = thenifyAll(fs, {}, ['readFile', 'writeFile']);

promisifiedFs.readFile('file.txt', 'utf8').then(contents => {
  console.log(contents);
}).catch(error => {
  console.log(error);
});

Other packages similar to thenify-all

Keywords

promisify

FAQs

Package last updated on 10 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts