NodeJS / Express: what is “app.use”?

后端 未结 23 1411
别跟我提以往
别跟我提以往 2020-11-29 14:48

In the docs for the NodeJS express module, the example code has app.use(...).

What is the use function and where is it defined?

23条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 15:16

    app.use is woks as middleware for app request. syntax

    app.use('pass request format',function which contain request response onject)
    

    example

    app.use('/',funtion(req,res){
     console.log(all request pass through it);
    // here u can check your authentication and other activities.
    })
    

    also you can use it in case of routing your request.

    app.use('/', roting_object);
    

提交回复
热议问题