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

284
Vistas
TypeError, is not a function error in NodejS

I have a class that contains few functions, putting one of then below,

const _ = require("lodash");
const ObjectId = require("mongoose").Types.ObjectId;
const mockLookUps = require(“../../data”).mockLookUps;

class XYZ {
   // ...... Other functions
   async getData() {
    return Promise.resolve(mockLookUps); // JSON Object
  }
}

module.exports = XYZ;

if I import that in other class like below,

const x = await XYZ.getData();

It is throwing me some is not a function error like this,

XYZ.getData is not a function

What is the mistake I'm making?

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

0

const xyz = new XYZ()
const data = await xyz.getData()

Could work

about 4 years ago · Juan Pablo Isaza Denunciar

0

1. You have to create a class instance first to call instance methods.

try this:

const xyz = new XYZ();
const result = await xyz.getData();

2. For your case try to make it static:

class XYZ {
   // ...... Other functions
   static async getData() {
    return Promise.resolve(mockLookUps); // JSON Object
  }
}

module.exports = XYZ;

and then you can use so:

const x = await XYZ.getData();
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