Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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
  • npm
  • Socket score

Version published
Weekly downloads
16M
increased by5.45%
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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc