Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
JSON empty when is called from another file

I'm learning NodeJS and MongoDB. I dont know what is happening with this function.

getAllUsers = async () = {

let user;
let result = await new Connection().connect();
if (result.status == "ok")
    {
        user = await User.find();

    }
return user;
};

If I make a console.log before return user, it works fine (just print an JSON array with all info of the collection)

The problem is when I call it from another file (in my case, the router). If I do this, I receive an empty json.

Why is this happening?

Thanks for your help!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When calling your function getAllUsers, you need to add await in front of it since it is an async function.

For example,

var listUsers = await getAllUsers();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda