Question
sequelize.import is not a function
I'm new to express.
I want to import files to sequelize and declared:
const model = sequelize.import(path.join(__dirname, file))
^
It returned the following type error
TypeError: sequelize.import is not a function
And then, edited code to
var model = require(path.join(__dirname, file))(sequelize, Sequelize);
^
Then the error is:
TypeError: require(...) is not a function
I think it is the error in importing stuff....
Here is my whole file code:
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const config = require('../config/config');
const db = {}
var __dirname = path.resolve();
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password,
config.db.options
)
fs
.readdirSync(__dirname)
.filter((file) =>
file !== 'index.js'
)
.forEach((file) => {
//const model = sequelize.import(path.join(__dirname, file))
var model = require(path.join(__dirname, file))(sequelize,
Sequelize);
db[model.name] = model
})
db.sequelize = sequelize
db.Sequelize = Sequelize
module.exports = db