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

Armel
  • 2,633
  • 6
  • 20
  • 33
J.S.C
  • 1,025
  • 1
  • 13
  • 21

1 Answers1

0

try let instead of const

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