Difference between app.all('*') and app.use('/')

后端 未结 7 1905
谎友^
谎友^ 2020-11-29 15:51

Is there a useful difference between app.all(\'*\', ... ) and app.use(\'/\', ...) in Node.JS Express?

7条回答
  •  春和景丽
    2020-11-29 16:34

    Yes, app.all() gets called when a particular URI is requested with any type of request method (POST, GET, PUT, or DELETE)

    On other hand app.use() is used for any middleware you might have and it mounts onto a path prefix, and will be called anytime a URI under that route is requested.

    Here is the documentation for app.all & app.use.

提交回复
热议问题