Questions tagged [node-promisify]

For questions specific to the node.js built-in utility function: util.promisify(). When using this tag also include the more generic [node.js] tag.

The utility function: util.promisify() was added in version 8. It is used to convert a -based function to a -based one.

Reference:

49 questions
8
votes
2 answers

TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function puppeteer node js

I am stuck here for a while I didn't understand the problem. Kindly someone enlightens me on this topic. here's the code. const puppeteer = require('puppeteer'); (async() => { let infourl =…
Hadi Husain
  • 109
  • 2
  • 6
7
votes
2 answers

Redis won't retrieve data from cache

I'm following a tutorial and I created a cache.js file that takes the mongoose query and JSON.stringifies it into the key for the values being returned by that query. The goal is to cache that and then append .cache() inside app.js where the…
user6680
  • 79
  • 6
  • 34
  • 78
3
votes
1 answer

How to mock a promisified and binded function in JEST?

I need to write a test for a function in jest. I have function like following: async function fun(conn, input){ const connection = conn.getConnection(); .... // some output gets generated from input // const processed_input =…
Anutrix
  • 145
  • 1
  • 9
3
votes
1 answer

Node.js redis promisify with .multi or .batch

Using the npm module 'redis', I've had no problem using utils promisify for single commands. const { promisify } = require("util"); const redis = require("redis"); const client = redis.createClient(); const hmgetAsync =…
Aaron
  • 193
  • 7
2
votes
1 answer

Promisifying custom functions with util.promisify

I would like to use util.promisify to promisify custom functions. However, util.promisify works for node-style methods that have an error-first callback as the last argument. How can I adjust my custom functions so that they will work with…
Nomad_Mio
  • 51
  • 5
2
votes
2 answers

npm error after installing Node.js: Cannot find module 'es6-promisify'

I have installed the latets version of Node.js for Windows. Whatever command I use I always get the same exception, i.e. when I type "npm -v" get this error message: Cannot find module 'es6-promisify' How to install "es6-promisify" when NPM is…
Chilly Code
  • 678
  • 2
  • 6
  • 17
2
votes
4 answers

Is this valid syntax for node/promisify async function?

I accidentally typed await(await stat(content... and it worked. Not sure if this is valid syntax, or there is a better way to do it? I'm trying to read all the files that are directories and do not match my regex. const fs = require('fs') const path…
ritchie
  • 405
  • 1
  • 4
  • 12
2
votes
2 answers

util.promisify converts async functions that use callbacks to Promises. Why doesn't it work with AWS S3.upload which follows that format?

Question: util.promisify converts an async function that uses the error-first callback style to a Promise. However it doesn't seem to work with AWS' S3.upload (scroll down to .upload) which is an async function that uses the error-first callback…
myNewAccount
  • 578
  • 5
  • 17
2
votes
1 answer

Promisify in redis client violates eslint rules

I wanted to use redis client with promisify: import type { RedisClient } from "redis"; import * as util from "util"; class MyClass { private redisClient: RedisClient; constructor(client: RedisClient) { this.redisClient = client; } …
pixel
  • 24,905
  • 36
  • 149
  • 251
2
votes
1 answer

promisify redis get and return the correct typescript type

The redis method get from redis node lib has this typescript signature: export interface Commands { get(key: string, cb?: Callback): R; } If I promisify the method, the signature is lost and the return type become any. I have…
ar099968
  • 6,963
  • 12
  • 64
  • 127
2
votes
1 answer

How do I use HMSET with node promisify

I am using node (TypeScript) and node-redis library. Since I use TypeScript, I also imported @types/redis. In addition, I read this article on how to promisify redis methods for TypeScript usage: https://flaviocopes.com/node-promisify/ My problem is…
Aleks
  • 5,674
  • 1
  • 28
  • 54
2
votes
2 answers

How does `await promisify(setTimeout)(ms)` work when the callback is missing?

For a simple async sleep function in JavaScript, await promisify(setTimeout)(ms) works! But how? The arguments look wrong. promisify passes an error callback, so the setTimeout call would be setTimeout(ms, errorCallback) which should not work, yet…
Patrick Fisher
  • 7,926
  • 5
  • 35
  • 28
2
votes
1 answer

Using util.promisify with exec is not resolving promise in git hook

According to the docs you can promisify NodeJS' require('child_process').exec by doing the following: const util = require('util'); const exec = util.promisify(require('child_process').exec); async function lsExample() { const { stdout, stderr }…
Antfish
  • 1,313
  • 2
  • 22
  • 41
2
votes
0 answers

Is there a "best" way to promisify and call a method function?

The way I see it, there are three ways to promisify and call a method function in one shot: const { promisify } = require('util'); const obj = { method: function (param, callback) { // Do something async with `this` …
Josh Klodnicki
  • 585
  • 6
  • 18
2
votes
0 answers

Nodejs: Override global.eval

Is there any way to safely override eval? Have tried directly overriding: var oldEval = global.eval; global.eval = function(){ // my logic global.a+=1; return oldEval.apply(this, arguments); } This somehow gives the following reference…
Anupam Juniwal
  • 309
  • 1
  • 3
  • 11
1
2 3 4