I want to create a sequelize DB connection in my index.js file and then "pass" it to whichever model is being CRUDed. Is this possible in NodeJS and how?
index.js
const { Sequelize, DataTypes, QueryTypes, Model } = require('@sequelize/core');
const sequelize= require('./config/db'); //Here the DB connection is being exported
Then the router is called which calls the Controller which then requires the Model class below...
modelName.js
class ModelName extends Model {}
ModelName.init {
fields.....
sequelize //This was initialized in 'index.js' and not in this file!
}
When I try this out, I get 'Model is not defined' and 'sequelize is not defined' errors.....I am completely new to nodeJS :)