So I have this code, which checks if a argument is whether given or not and has a value or not.
const isSetAndNotEmpty = (parameter) => {
return (req, res, next) => {
//Define param ( is there a way to make this working with the parameter from above )
const param = req.query.id;
//Check param
if (!param || typeof (param) === 'undefined') {
return res.json({
success: false,
message: `Argument '${parameter}' is missing or empty!`
});
}
next();
};
};
Is there a way to give the param variable the same value as the parameter? Because the way I see it works is that whatever I give the req.query.xxx it will take it as a query parameter.
Just saying req.query.parameter is not working because of the reason that it will be taken as a query parameter.