How to get the string returned by fetch directly

I want to use fetch to request a string from the background api. Is there any way to directly take the string out and assign it to the variable?
my original way of writing is this:

var text = "";
fetch(`http://127.0.0.1:8080/`,{
        method: "GET"
    }).then(res => res.text()).then(
      data => {
            text = data
        }
    )
    

after reading many tutorials online, I have converted the data into strings with .text (). It seems that there is still a problem with writing this. How can I take the results out and assign values to external variables? Please give me your advice.
I want to pass the value to the external text variable.


there is no problem with writing this way, but because ajax is asynchronous, you can't get text directly in the code behind fetch

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bf1f-40061.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bf1f-40061.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?