Monday 15 June 2015

node.js - Expressjs middleware example -


Hello, I have a code in app.js , which looks like this:

  app Uses ('/ someurl', Required ('. / Middleware / somemodule'));   

- App instead of app.

And the module looks like this:

  if (process.env.BLALAL == = Undefined) {Throw "error: process.env.BLALAL === undefined"; } Module.exports = function (req, res, next) {...}   

Is this a bad practice?

As told on:

app. ) Methods provide routing functionality in Express, where VERB is one of HTTP verbs, such as app.post () .

The "mount" path has been snoozed and is not visible to the middleware function. The main effect of this feature is that the mounted middleware code can work without regard to its "prefix" pathname without changes.

IMO

The functionality can be virtually the same, but an implicit meaning means the only way through the app.overb API Should be set, while any middleware should be set through the app.use API.

Modify intermediate request or feedback objects , or Inject the functionality of other modules which can answer request , or not.

Is a good example. It can actually be one or the other, but injected into the middle of the other app object as the middleware.

No comments:

Post a Comment