Q
Q
Quambaras2021-02-11 18:38:01
Node.js
Quambaras, 2021-02-11 18:38:01

Why is an empty object returned?

There is a method, all data from the database is received in the console

get = async () => {
        const allUsers = await user.findAll({raw:true});
        console.log(allUsers)
        return allUsers;
    }

Services code
getUser = () => {
        return MethodsDB.get();
    }

and controllers
get = (req, res) => {
        res
            .header('Access-Control-Allow-Origin', '*')
            .status(200)
            .send(user: this.service.getUser())
    }


But an empty object comes to me, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2021-02-11
@Quambaras

Because you are mixing synchronous and asynchronous code, most likely.
If asynchronous functions are pulled from synchronous ones, then you will get not their result, but a promise.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question