I found it frustrating to do function ***(req, res){ ... }
every time when working with promises. So I had an idea of making a top, reference objects instead, Req
and Res
let Req;
let Res;
// i can also do "const { username } = Req.body" to make "username" avaliable to all functions
function promise() { return Promise.resolve(); }
function promise2() { Res.send('test'); }
module.exports = (req, res, next) => {
Req = req
Res = res
return promise().then(() => promise2());
}
What are your thoughts on this, pros and cons? If this is anti-patern let me know and suggest a preferred way.
Thanks