Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!