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

DOCKER ARG instruction as opposed to ENV instruction

  In Docker, ARG and ENV are used to define environment variables. The ARG instruction defines variables that users can pass to the builder ...