aUtil.js
module.exports = {
successTrue: function(data) {
return { data: data, success: true };
},
isLoggedin: async (req, res) {
//decoded token in req header
//if decoded token success,
res.json(this.successTrue(req.decoded));
}
}
that function call in test.js
router.get('/check', aUtil.isLoggedin, async (req, res) => { ... })
I want to use the function above in that function.
But I keep getting errors.
ReferenceError: successTrue is not defined
I tried many ways.
- insert 'const aUtil = require('./aUtil')`
- change to
'res.json(successTrue( ... )'
exports.successTrue = function () { }this is alot more cleanerisLoggedindoesn't need to beasynceither.