Monday, July 19, 2021

TypeError : Router.user() requires a middleware function but got a undefined

 This most probably indicates that your api is not being set properly. Check whether the api file ahas module.exported , you properly express.Router and returning it. In my case I forgot to return the api, and got the error. 



module.exports = function(appexpress) {
    var api = express.Router();


/////////////////////////////////////////////////////////////
    api.get("/users"function(reqres) {

        User.find({} , function(errusers) {
            if (err)
            {
                res.send(err);
            }
            else 
            {
                res.json(users);
            }
        });
    } );
/////////////////////////////////////////////////////////////

    return api; //<= forgot this!
}

No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...