osmanraifgunes osmanraifgunes - 16 days ago 5
Node.js Question

node.js extends foo is not a function

I am using node.js with es6 beside sequelizejs.

My base class (base.js):

class base {

constructor(table) {
this._table = table;
}

all(query) {
this._table.findAll({
}).then(function (dbStatus) {
return new Promise((resolve, reject) => {
resolve(dbStatus);
})
});
};
}


My derived class (city.js):

var util = require('util');
var base = new require('../base');


class city extends base {
constructor() {
super(db.city);
}
}

module.exports = city;


Usage of derived class (cityrest.js) :

var city = new require('../../dataBaseOperations/city')
var app = express();

app.get('/all', function (req, res, next) {
city.all(req.query, function (result, resultData) {
if (result) {
res.json({
data: {
success: result,
content: resultData,
message: 'messageContent'
}
});
}

})
})


Error is : TypeError: city.all is not a function at cityrest.js

Answer

Require returns an object.
Try this:

var City = require('../../dataBaseOperations/city')
var city = new City()