I'm new to NodeJS and coding in general and while looking for answers to read the contents of a Node.js stream into a string variable on StackOverflow I came across this answer: https://stackoverflow.com/a/63361543/15144023
The following code can be seen in the answer:
// lets have a ReadableStream as a stream variable
const chunks = [];
for await (let chunk of stream) {
chunks.push(chunk)
}
const buffer = Buffer.concat(chunks);
const str = buffer.toString("utf-8")
(credit to Traycho Ivanov for the answer)
I get "Unexpected reserved word" in the await word and I can' understand how to fix it and how to actually use it. Unfortunately being new on StackOverflow doesn't allow me to comment on the answer, being the reason I used this approach.