53 questions
0
votes
0
answers
16
views
How do deal with 'setImmediate()' function when migrating callback function to async await?
I am trying to migrate old legacy NodeJS code that looks like:
function x(data, callback) {
doSomethingWithData(data);
if(data.x) {
setImmediate(callback, "A");
}
...
-1
votes
1
answer
208
views
How to mock promisified child process exec with Jest
I'm trying to write a test for this piece of code:
const util = require('node:util')
const exec = util.promisify(require('node:child_process').exec)
class Command {
async execute(command) {
try ...
1
vote
0
answers
117
views
Why does TypeScript pick the wrong overloaded function? [duplicate]
I'm using promisify with mysql2's execute method, and when I do so it always seems to pick the last overload even if it doesn't match the parameters I've provided. I've reduced the problem down to ...
0
votes
0
answers
70
views
Running worker file in a loop gives error for nodeJs application
When I am running a worker file inside a nodeJs application in a loop it gives error as :
Module did not self-register: '/server/node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding....
0
votes
1
answer
345
views
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 ...
1
vote
1
answer
735
views
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 ...
0
votes
1
answer
712
views
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 ...
0
votes
0
answers
71
views
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 ...
0
votes
1
answer
107
views
Promisify `execFile` is not resolving when opening a dmg file
This is an extremely weird bug I'm running into. Basically, I have this execFile:
export const execFile = util.promisify(childProcess.execFile);
When I use this to open up a dmg file that is currently ...
4
votes
1
answer
4k
views
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 ...
3
votes
2
answers
4k
views
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-...
-1
votes
1
answer
88
views
Calling a function after everything else is finished
the function generirajFakturi is used to create some data in a table through sequelize, and after adding everything that it needs to add it should call the function that is at the end dodeliNagradi ...
0
votes
1
answer
2k
views
Returning Promise { undefined } in NodeJS when making a function call
I am trying to call a function and wait till the function gets data before further statements get executed. I am new to node js and async/await and promises. I tried some solutions but doesn't work it ...
0
votes
1
answer
126
views
Why don't my promisify and jwt return values or errors?
if(req.cookies.token_name) {
try {
const decoded = await promisify(jwt.verifiy)(req.cookies.token_name,
process.env.jwtsecret);
console.log(decoded);
}
catch ...
5
votes
1
answer
2k
views
How to mock a promisified and bound function?
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 ...