module.exports.variable
vs module.exports={variable}
Consider the code below from fileOne.js
module.exports = {
x,
v
}
async function v(){
return "v"
}
var x = "x"
fileTwo.js
const y = require('./fileOne');
console.log(y.x, y.v());
// returns undefined and "v".
If I change fileOne.js code to:
module.exports = {
//x,
v
}
async function v(){
return "v"
}
module.exports.x = "x"
... the code from fileTwo.js
logs x
and v
to the console.
What is the difference between module.exports.variable
and module.exports={variable}
and why does the former work for variables but the latter does not?