express.Router() vs. app.get

后端 未结 4 2060
走了就别回头了
走了就别回头了 2020-12-31 10:22

I am using Express 4 server for Node.js

There is a router baked into Express like so:

in app.js

    var router =         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 10:55

    I actually think that this is in fact the preferred way. You define your routes separately and simply use it in your app. It provides a nice separation of concerns. It also makes testing your routes quite easy. And yes, you can create a solid RESTful backend using express.Router. Also, it has all the basic HTTP verbs like get, post, put, delete, patch etc. attached to it.

提交回复
热议问题