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
2
votes
0 answers

Promisify of Express middleware

How to promisify function what is Express middleware (for example authenticate(arg1, arg2)(req, res, next))? I tried promisify method from util and also from es6-promisify but none of those work. I am getting error: TypeError: authenticate(...) is…
Baterka
  • 3,075
  • 5
  • 31
  • 60
1
vote
1 answer

NodeJS: Await Skips Catch Block and Exits Function. Why?

this is my first question so give me feedback please. The file in question is a very large file so I am thinking to use asynchronous reading. Expected behavior: Success: "await" will cause the execution of the code to block until the file has been…
1
vote
1 answer

How to promisify a mysql pool connection in Node js?

I'm trying to understand how to use the node js util to promisify pool connections. I would keep my code clean using async/await logic ( without the callback hell, that I really don't like especially with transactions ). here is my config…
RoccoDen91
  • 125
  • 3
  • 9
1
vote
1 answer

How does promisify know which variable to return?

I used util.promisify on this sqlite3 function: // Before db.each("Select * from example;", (error, row) => console.table(row)); db.each = util.promisify(db.each); // After async function getRow() try { console.table(await…
ma1234
  • 445
  • 1
  • 4
  • 9
1
vote
1 answer

Node: asynchronous version of readline with util.promisify

I'm trying to create an asynchronous version of readline with promisify. Something to use this way: import { Cli } from '../services/Cli'; const cli = new Cli(); const main = async () => { await cli.question('What is your name ? '); await…
Emille C.
  • 562
  • 1
  • 7
  • 23
1
vote
2 answers

How to use await with promisify for crypto.randomBytes?

I'm writing a function to generate a random key using crypto.randomBytes, which takes a callback. I'd prefer to use async await so I'm trying to use util.promisify to wraprandom bytes like this: const crypto = require('crypto'); const util =…
Huggzorx
  • 144
  • 1
  • 13
1
vote
2 answers

Problems with query and express in nodeJS

I'm developing a web page using express for the server with nodeJS. I'm with the sign up page, and I'm trying to validate user inserted data, but when I make the query I get an error. auth.js const express = require('express'); const router =…
arevilla009
  • 429
  • 3
  • 18
1
vote
1 answer

Promisify without object instance

We can promisify mysql pool getConnection function if we have already created the pool, like this: const mysql = require('mysql'); const util = require('util'); const mysqlPool = mysql.createPool(CONFIG); const getConnectionPm =…
Amir
  • 996
  • 7
  • 17
1
vote
1 answer

Why would promisify cause a loop to take massively longer?

I have an app which has to extract color info from a video and it does this by analyzing each frame. First I extract the frames and then load an array of their locations in memory. As you might imagine, for even a small video it can be in the…
user4747724
1
vote
2 answers

Type functions that can be promsified

I'm working on adding separate types to node-vagrant NPM library to use in Typescript, to be contributed under DefinitelyTyped. However, one of the methods of the library is promisify which makes all other functions in the library then return a…
MasterOdin
  • 7,117
  • 1
  • 20
  • 35
1
vote
3 answers

Can't promisify callback based function

I want to use the library astro-js where a typical call in their docs looks like this: const aztroJs = require("aztro-js"); //Get all horoscope i.e. today's, yesterday's and tomorrow's horoscope aztroJs.getAllHoroscope(sign, function(res) { …
German
  • 10,263
  • 4
  • 40
  • 56
0
votes
1 answer

Am I using promisify() with bind() correctly?

I am writing middleware to return database queries using SQLite3 and Next.js. Here is a snippet of code that I wrote to return the contents of a DB table. It appears to work, and my checks of sources appear solid, with mixed reviews about the use…
chrisroode
  • 77
  • 10
0
votes
1 answer

NodeJS promisified glob: Expected 2 arguments, but got 1

Basically, this error suddenly appeared after I updated all my NPM dependencies in the project and this affected the situation (likely particularly glob or typescript). The fragment of code below comes from a program, used in a Discord.js bot for…
123253
  • 51
  • 3
0
votes
1 answer

throw new TypeError("expecting a function but got " + util.classString(fn)); TypeError: expecting a function but got [object Undefined]

While running node app.js the Express server is connecting properly and the MongoDB is connecting correctly, but I am facing a problem in the node module as mentioned above. The complete log is pasted below: throw new TypeError("expecting a…
0
votes
0 answers

Javascript - Convert function that have a least two callbacks style to promise style

I moving from callback style to promise style to avoid the callback that made me hard to maintain the code. I use util module to import and convert the callback function with util.promisify(), but the question is if the function have at least two…