TypeError: Cannot read properties of undefined (reading 'database') in NodeJS on AWS

Viewed 292

I've an error comes when I execute (npm start) :

TypeError: Cannot read properties of undefined (reading 'database')
at Object.<anonymous> (C:\Users\Ahmed Ra'fat\Downloads\AnotherDayWeb-master\AnotherDayWeb-master\passport.js:11:45)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Ahmed Ra'fat\Downloads\AnotherDayWeb-master\AnotherDayWeb-master\index.js:24:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

I guess this is because environment variables are not defined well in passport.js

database is defined as the following:

local: {
    //url to be used in link generation
    url: 'http://localhost:8081/',
    database: {
      host:   'aa1kiub44j3f2lh.cch13jyjjqb1.us-west-2.rds.amazonaws.com',
      user:   'anotherdayuser',
      pw:     'anotherdayuser',
      port:   '3306',
      db:     'ebdb'
  },

and I call it in passport.js as the following:

var connection = mysql.createConnection({
host: config[""+process.env.env_var+""].database.host,
user: config[""+process.env.env_var+""].database.user,
password: config[""+process.env.env_var+""].database.pw,
database: config[""+process.env.env_var+""].database.db
});
0 Answers
Related