Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140500

TypeError: Cannot read property 'database' of undefined

$
0
0

I have two files-config.js and index.js The code I have written is as follows-

config.js-

module.exports={
    port:process.env.PORT || 8081,
    db:{
        database:process.env.DB_NAME|| 'tabtracker',
        user:process.env.DB_USER || 'tabtracker',
        password:process.env.DB_PASS|| 'tabtracker',
        options:{
            dialect:process.env.DIALECT ||'sqlite',
            host:process.env.HOST ||'localhost', 
            storage:'./tabtracker.sqlite'

        }
    }
}

index.js-

const fs=require('fs')
const path=require('path')
const Sequelize=require('sequelize')
const config=require('../config/config')
const db={}


const sequelize=new Sequelize(

    config.db.database,
    config.db.password,
    config.db.user,
    config.db.options
)


fs.readdirSync(__dirname)
 .filter((file)=>{
     file!=='index.js'
 }
 )
.forEach(file=>{
    const model=sequelize.import(path.join(__dirname,file));
    db[model.name]=model
})

db.sequelize=sequelize
db.Sequelize=Sequelize
module.exports=db

Why it is throwing error? I have imported the config.js properly in index.js. I have also declared config file properly.


Viewing all articles
Browse latest Browse all 140500

Latest Images

Trending Articles



Latest Images