Express: app.use - allow to pass an array of middleware without specifying a path.

Created on 6 Mar 2017  路  1Comment  路  Source: expressjs/express

I think it would make our development process faster, our code cleaner if we can do this:

app.use([
  bodyParser.json(),
  bodyParser.urlencoded({ extended: true }),
  expressValidator(),
  passport.initialize(),
  passport.session()
]);

Instead of

  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(expressValidator());
  app.use(passport.initialize());
  app.use(passport.session());

What do you think?

4.x question

Most helpful comment

I couldn't agree more, which is why we already allow that :) Here is a test for that feature: https://github.com/expressjs/express/blob/master/test/app.use.js#L170-L196

>All comments

I couldn't agree more, which is why we already allow that :) Here is a test for that feature: https://github.com/expressjs/express/blob/master/test/app.use.js#L170-L196

Was this page helpful?
0 / 5 - 0 ratings