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

Related issues

snowdream picture snowdream  路  3Comments

extensionsapp picture extensionsapp  路  3Comments

AndrewEQ picture AndrewEQ  路  4Comments

gaurav5430 picture gaurav5430  路  3Comments

HafidAbnaou picture HafidAbnaou  路  3Comments