1

I'm trying to access my config.js file in all modules of my project but I can't even though the config file is defined as global.

Here's my packaging:

enter image description here

in the server.js I have defined:

global.config = require('./app/config');

I can access the properties of config in server.js but when I try to use config in other files such as user.js I get this error:

config is not defined

I don't know how to fix the way I'm defining this global variable.

2 Answers2

1

Most likely config.js file isn't imported into the runtime of the program that you start. Make sure you import config.js at least once into your runtime

GProst
  • 9,229
  • 3
  • 25
  • 47
1

it doesn't make any sense but when I moved the global variable above the variable which contained the router it worked.

global.config = require("./app/config");
const routeHandler = require('./app/routes/index');