I can read a local file and print it out with fetch
fetch(localFileUrl)
.then(response => response.text())
.then(text => console.log(text))
but I couldn't figure a way to save the content into a global variable (and immediately use it).
I tried
var fileContent = fetch(localFileUrl)
.then(response => { return response.text() })
console.log(fileContent)
only to get Promise {<pending>}
also tried
var fileContent = "init"
fetch(localFileUrl)
.then(response => response.text())
.then(text => fileContent = text)
console.log(fileContent)
but it prints out init
, not file content
How do I force thie promise evaulated before executing later code?