Reputation: 3259
I am new to Typescript and this is the first time for me dealing with async
and await
. I have an express
endpoint which is not async. Inside I have a for-loop that seems to require await. What would be the common way in TypeScript to iterate over this loop?
app.get("/", function (req, res) {
const resultIterator = client.query(
'SELECT username FROM users;'
);
for await (const row of resultIterator) { <--- await illegal here
// 'Hello world!'
}
});
Upvotes: 1
Views: 395
Reputation: 953
app.get("/", async function (req, res) {
Express endpoints don't care whether they are async or not. You can always make them async.
You need the async keyword for await to work.
Upvotes: 2