#StackBounty: #javascript #node.js #typescript #postgresql #sequelize.js postgres init code with multiple sequelize

Bounty: 100

I am trying to convert js code to ts code (and understanding why something have been done).

This my JS code

use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.js')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  sequelize = new Sequelize(config.database, config.username, config.password, config);

Object.keys(db).forEach(modelName => {
  if (db[modelName].associate) {

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

Here, there are multiple sequalise

db.sequelize = sequelize;
db.Sequelize = Sequelize;

Can someone please help me in understand meaning, purpose and why both of them exist? and where we would use each of them.

I am able to make sense for sequelize but not for Sequelize. like we already have used new Sequelize( so why would we add it in db object?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.