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();