Node Express 4 middleware after routes

前端 未结 5 475
后悔当初
后悔当初 2021-01-01 10:22

Following the upgrade to Express 4, and the removal of app.router, I\'m struggling to get middleware to execute after routes execute.

e.g. the following code correct

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 10:48

    Order is important http://expressjs.com/4x/api.html#app.use

    express.use( function( req, res, next ) {
      console.log( "world" );
      next();
    });
    express.get( "/", function( req, res ) {
      res.send( "hello" );
    });
    

提交回复
热议问题