For being able to use a variable in diferent files you can define the variable the normal way you would do in the main file, then at the end of the file you can do module.exports to export the varible, lets say this is on index.js:
let variable1 = "Hello"
module.exports = {
variable1
}
Then on the 2º file where you want to use the variable you would require the index.js and that would have every variable that was exported
const variableX = require("./index.js")
console.log(variableX)
And as you can see, on the 2º file you would have on console.log "Hello".
Note: inside the require you put the path to the file you want to get the data from.