I just raised this issue with Express, and I'm interested in what StackOverflow thinks about it:
https://github.com/strongloop/express/issues/2831
My question is why Express forbids the developer from transferring data directly between intermediate functions and basically forces you to assign temporary data to the request object in what I always considered a rather inconvenient destination.
more specific:
Transferring data between intermediate functions usually involves doing this.
req.specialData = {} next();
however, perhaps it would be much simpler and more productive (!) if it were possible
next(null,data);
or
function mySpecialMiddleWare(req,res,next,data){}
// now call the function above
mySpecialMiddleWare(req,res,next, {some:data});
, Express , , , , , function.length > 3 function.length === 4...
, , - ?
///, , req??
, , ?
, Express , .
, API - , , . , - , , . , API . . , , , , .
, . , , , cookie. , , . , , .
, , - , arity ( ) API- TJ. , , API.
- , . , . , hapi, restify .., .
- , . .
- , . , , , , .
- "" , , , , , - JavaScript, TypeScript Haskell "" .
, Express , , , Express middlewares res.locals. . Expressjs-plus. .
javascript, . (varInResLocals, varInReqParams, ) .
.
var express = require('express'); var ExpressPlus = require('expressjs-plus').ExpressPlus; var app = express(); // simple handler example var userHandler = function(param, paramsArray, req, res){ if(param !== 'user') return false; paramsArray.push("USER WAS FOUND!"); return true; }; // this handler allows you to pass res.locals properties between your middlewares seemingly, // it the parameter was found in locals, it attaches it to paramsArray. var resLocalsHandler = function(param, paramsArray, req, res){ if(param in res.locals){ paramsArray.push(res.locals[param]); return true; }else return false; }; var appPlus = new ExpressPlus(app, [userHandler, resLocalsHandler], []); var regularFunction = function(user, id, cb){ return cb(null, { response: {user: user, id: id}, status: 200, resLocalsVar: "passVar" }); }; // resLocalsVar was passed in a previous method var regularFunction2 = function(resLocalsVar, user, id, cb){ // now you can have access to it console.log(resLocalsVar); return cb(null); }; // the responder at the end will use res.locals.status and res.locals.response to issue an HTTP response app.use(appPlus.GMV(regularFunction), appPlus.GMV(regularFunction2), appPlus.responder); // adds error handlers, it will add a default error handler along with the list of error handlers passed // in this case, no error handlers were passed appPlus.setErrorHandlers(); app.listen(3001, function(){ console.log('Listening!'); });
Source: https://habr.com/ru/post/1620652/More articles:Do regular email clients provide pre-extraction of links, not images? - htmlIntegration of functions returning an array in Python - pythonBingpreview revokes one time link in email - emailGuard Ruby classes with class-level metaprogramming against multiple loads - ruby | fooobar.comAccess the real file name of the symbolic linked file - ruby | fooobar.comКак зарегистрировать обработчик сообщений перед вызовом ShowDialog()? - c#How to remove empty elements after class? (JQuery) - javascriptHow to skip yellow VM scripts when debugging in Chrome - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1620656/using-css-to-style-elements-drawn-to-a-canvas&usg=ALkJrhigzBkQzy4lyPkFhgpN5ZsEUpkjqgJava - Как unit test проблемы с TimSort и "общие нарушения контракта" - javaAll Articles