Skip to content Skip to sidebar Skip to footer

TypeError: Database Is Not A Constructor When Initializing Constructor

I have a Database object (database.js) that looks like this: //create the database function Database(host, dbuser, dbpassword){ this.host = host; this.dbuser = dbuser;

Solution 1:

To export your Database "class" use

module.exports = Database;

And to use

var Database = require('./database.js');

new Database(...);

Here you have a good tutorial about how to use export/require


Is still strongly recommend to upgrade to ES6.


Post a Comment for "TypeError: Database Is Not A Constructor When Initializing Constructor"