Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
TypeError: Class extends value #<Object> is not a constructor or null

I'm new at nodejs. I wanna make a class to do some queries in the database. so I need a database connection. I tried doing this by OOP to have a clean code. so I used 2 classes. first-class (I named it server) tried to make a connection. and the second class (named update_currencies) extended the class named 'server'. in the end, I tried to run an update.js-file but I take an Error: [TypeError: Class extends value #<Object> is not a constructor or null]

I checked the address at require-functions but they seem right. and I tested setQuery-method in the server-class and it works without error. but when I write it in separate classes like
this code, I take an Error.

these codes take me Error:

server.js :

const mysql = require('mysql')

class server {

  connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'testt'
  });

  constructor() {
    this.connection.connect()
  }
  
  destructor() {
    this.connection.end()
  }
}

module.exports = {
  server,
};

update.js :

const server = require("./server");
class update_currencies extends server {
  setQuery() {
    this.connection.query("UPDATE `currencies` SET `value` = '2.5' WHERE `currencies`.`name` = 'Dollar';",
      (err) => {
        if (err) throw err
      });
  }
}

module.exports = {
  update_currencies,
}

var Jafar = new update_currencies();
Jafar.setQuery();
Jafar.destructor();

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda