0

I got this function

module.exports.usersdb = async function (req, res) {

    const arr = ["apple", "banana", "orange"];

    const encodearray = arr.map(data=> _token.signToken(data));

    console.log(encodearray);
}

but the output is a promise object like: "Promise: {result}"

How can i get it as a string?

this is the signtoken function which is exported

exports.signToken = function (data) {
    return new Promise((resolve, reject) => {

        try {

            const token = jwt.sign(data, _sign, algorithm);
            resolve(token)

        } catch (err) {

            return reject("An error has occurred " + err)

        }
    })
}
Alexandro Pineda
  • 706
  • 3
  • 10
  • 2
    Why are you using promises when you're not using any asynchronous code? You're using the synchronous version of `jwt.sign()`. – robertklep Sep 07 '22 at 17:47
  • I think you should be good to go if you use await the response of _token.SignToken function – Arun Bohra Sep 07 '22 at 17:48
  • `encodearray` looks like an array of promises. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all – James Sep 07 '22 at 17:48

0 Answers0