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

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...