2

When i load my custom made file globally, it is not loaded properly and returns an empty object:

const msgq = require('../db/message_queue.js');

var getList = async(url) => {
    console.log(msgq);
    ...
}

However, if i load locally inside the function, it works as I expected. What is the reason behind this?:

var getList = async(url) => {
    const msgq = require('../db/message_queue.js');  
    console.log(msgq);
    ...
}

Though, the weird thing is that in other parts of my code, i declared it globally and used it with no problem...

running on ExpressJS

Pingolin
  • 3,161
  • 6
  • 25
  • 40
J.S.C
  • 1,323
  • 3
  • 16
  • 22

1 Answers1

0

try let instead of const

    let msgq = require('../db/message_queue.js');