module.exports.variable is a property on the module.exports object. When you initialize your module, you assign the value of variable to that module.exports.variable property and that value is undefined at the time you assign it (because the initialize() function has not yet been called).
So, when your module is done initializing itself, module.exports.variable is undefined.
Then, sometime later someone else calls module.exports.initialize() and that changes the local variable within your module to "123". That does not affect the value of the module.exports.variable property at all. It remains undefined.
In the future, please don't give either a property or a variable the name variable as it makes it very difficult to document or discuss. A different name that doesn't conflict with the English definition of the word variable would simplify discussing this code.
What you can do instead is export an object instead of a plain value.
let myObj = { name: "John"};
module.exports.setName = (name) => {
myObj.name = name;
};
module.exports.sharedObj = myObj;
Then, why you import it somewhere else
const aModule = require('./otherModule');
console.log(aModule.sharedObj); // {name: "John"}
aModule.setName("Bob");
console.log(aModule.sharedObj); // {name: "Bob"}
Because objects in Javascript are assigned by pointer, when you did module.exports.sharedObj = myObj; in the module initialization, it put a pointer to myObj into module.exports.sharedObj so when myObj changes, anyone viewing module.exports.sharedObj will see that change too. This only works this way for objects in Javascript, not for other types of values (strings, numbers, etc...).
initialize()before you exported the variable's value?undefinedhas been exported