Socket
Socket
Sign inDemoInstall

thenify

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    thenify

Promisify a callback-based function


Version published
Weekly downloads
12M
increased by2.34%
Maintainers
1
Install size
11.2 kB
Created
Weekly downloads
 

Package description

What is thenify?

The thenify npm package is designed to convert Node.js callback-style functions to functions that return a promise. This is particularly useful when working with older Node.js APIs or third-party libraries that do not natively support promises, allowing developers to write cleaner, more modern asynchronous code using async/await or .then() syntax.

What are thenify's main functionalities?

Converting a callback-style function to a promise-returning function

This feature allows you to wrap a traditional Node.js callback-style function, such as `fs.readFile`, in a way that it returns a promise. This enables the use of `.then()` and `.catch()` for cleaner asynchronous control flow.

const thenify = require('thenify');
const fs = require('fs');
const readFile = thenify(fs.readFile);

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

Other packages similar to thenify

Readme

Source

thenify

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Promisify a callback-based function.

  • Preserves function names
  • Uses a native promise implementation if available and tries to fall back to bluebird
  • Converts multiple arguments from the callback into an Array
  • Resulting function never deoptimizes

An added benefit is that thrown errors in that async function will be caught by the promise!

API

var thenify = require('thenify');

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
});

var fn = thenify([name], fn)

Promisifies a function. Optionally set a custom name to the function, defaulting to fn.name.

Keywords

FAQs

Last updated on 17 Dec 2014

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc