DEV Community

Discussion on: Writing Async/Await Middleware in Express

Collapse
 
josheriff profile image
Jose

I mean this:

const endpoint = 'jsonplaceholder.typicode.com/posts/1';
const asyncMiddleware = async (req,res) => {
const data = await PromiseBasedDataRequest(endpoint);
req.data = await data.json() // if I remember well data.json() its a
//promise too thats why about another
//await
return req.data
}

// the workflow continues

Async await it's almost have a "syncronous" code.