Q: TypeError: Cannot read property 'database' of undefined. Any ideas? I am working at this project https://github.com/ameCont/vue.git
Index.js file:
const fs = require('fs')
const path = require('path')
const Sequelize = require('sequelize')
const config = require('../config/config')
const db = {}

//console.log(config)

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))
        db[model.name] = model
    })

    db.sequelize = sequelize
    db.Sequelize = Sequelize

    module.exports = db

When I run 
npm start

inside server directory I get the error
/home/ubuntu/vue/server/src/models/index.js:10
    config.db.database,
              ^

TypeError: Cannot read property 'database' of undefined
    at Object.<anonymous> (/home/ubuntu/vue/server/src/models/index.js:10:15)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/ubuntu/vue/server/src/app.js:7:21)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
[nodemon] app crashed - waiting for file changes before starting...

My config.js file contains:
module.exports = {
    port: process.env.PORT || 8081,
    db: {
        database: process.env.DB_NAME || 'vue',
        user: process.env.DB_USER || 'vue',
        password: process.env.DB_PASS || 'vue',
        options: {
            dialect: process.env.DIALECT || 'sqlite',
            host: process.env.HOST || 'localhost',
            storage: 'vue.sqlite.sql'
        }
    }
}

It has || 'vue' so it shouldn't need a real database (I created one but the issue is the same)
I am beginner with vue.
Here JS: firebase.init error: TypeError: Cannot read property 'database' of undefined, the solution was to install some plugins.
But in my case which plugins?
If it helps, when I run
npm install sqlite3

I get this
> sqlite3@4.2.0 install /home/ubuntu/vue/server/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Pre-built binaries not installable for sqlite3@4.2.0 and node@10.19.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding' 
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/ubuntu/vue/server/node_modules/sqlite3/build'
gyp ERR! System Linux 5.4.0-26-generic
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "configure" "--fallback-to-build" "--module=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /home/ubuntu/vue/server/node_modules/sqlite3
gyp ERR! node -v v10.19.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/node /usr/bin/node-gyp configure --fallback-to-build --module=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/ubuntu/vue/server/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
node-pre-gyp ERR! System Linux 5.4.0-26-generic
node-pre-gyp ERR! command "/usr/bin/node" "/home/ubuntu/vue/server/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/ubuntu/vue/server/node_modules/sqlite3
node-pre-gyp ERR! node -v v10.19.0
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok 
Failed to execute '/usr/bin/node /usr/bin/node-gyp configure --fallback-to-build --module=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/ubuntu/vue/server/node_modules/sqlite3/lib/binding/node-v64-linux-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
npm WARN eslint-plugin-import@2.20.2 requires a peer of eslint@2.x - 6.x but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-vue@6.2.2 requires a peer of eslint@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN server@1.0.0 No description
npm WARN server@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@4.2.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sqlite3@4.2.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Also, this topic doesn't help TypeError: Cannot read property 'database' of undefined
because I do have const config = require('../config/config')
Thanks for help!

A: Actually, in your config you have two exports, so for correctly accessing it you should name the exported objects:
module.exports.config = {
    port: process.env.PORT || 8081,
    db: {
        database: process.env.DB_NAME || 'vue',
        user: process.env.DB_USER || 'vue',
        password: process.env.DB_PASS || 'vue',
        options: {
            dialect: process.env.DIALECT || 'sqlite',
            host: process.env.HOST || 'localhost',
            storage: 'vue.sqlite.sql'
        }
    }
}

module.exports.otherConfigs = {
    // other configs ..
}

Then in model's index.js you import the configs like that:
const { config, otherConfigs } = require('../config/config')

