Monday 12 February 2018

How do you really implement async-methods in express routes?

Hi,Im making a move from .NET/C# to the wonderful world of open source. Im making a small rest api in nodejs with postgres as the database, but I cant seem to figure out how to implement the async-methods in my express-routes. Whatever I do, they never "fulfill" and are always undefined. I have implemented according to the best practice on the ps-homepage, but I cant seem to wrap my head around how you await for a async-method to finish?Example:router.get('/', auth, async (req, res) => { var text = 'SELECT * FROM public.sale WHERE product.companyID = $1' const { rows } = await db.query(text, [1]) res.send(rows[0]) }) How do I await a call like this, and how do you "catch" errors that come out of it?Thanks for all help on this as the whole async-thinking is somehow missing from me.I've been using the projects guide to setup according to this: http://ift.tt/2o0T1c1

Submitted February 12, 2018 at 08:18PM by smallpom

No comments:

Post a Comment