Passing in Async functions to Node.js Express.js router

前端 未结 5 2050
别跟我提以往
别跟我提以往 2021-02-04 05:37

This seems like a straightforward google, but I can\'t seem to find the answer...

Can you pass in ES7 async functions to the Express router?

Example:

<         


        
5条回答
  •  清歌不尽
    2021-02-04 06:12

    I think you can't do it directly because exceptions are not caught and the function won't return if one is thrown. This article explains how to create a wrapper function to make it work: http://thecodebarbarian.com/using-async-await-with-mocha-express-and-mongoose.html

    I haven't tried it but was investigating this recently.

提交回复
热议问题