Express routes: .get() requires callback functions but got a [object Object]

Solution 1:

You export an object with the key list having the your function as value.

So to access your function you would need to do this require('./routes/user.js').list

Or with your code user.list.list.

To solve this you have two possibilities.

Either write:

var user = {
  list : require('./routes/user.js').list
}

Or:

module.exports = function(req, res){
   res.send("respond with a resource");
};

EDIT

If your routes/user.js will probably later look like this:

module.exports.list = function(req, res){
   res.send("respond with a resource");
};

module.exports.delete = function(req, res){
   res.send("delete user");
};

If yes then you can just write it that way in your routes.js:

var user = require('./routes/user.js');

Solution 2:

I think what you want is:

module.exports = function (app) {

  var user = {
      list : function(request, response){  
                    require('./routes/user.js');
            } 
}
    } 
  , index = {
      index : function(request, response){ 
          require('./routes/index.js') 
        }
    } 


  app.get('/', function(request, response){
    response.send('You made it to the home page.')
  });

  app.get('/users', user.list);
}

In this way give a callback to the route and this callback execute the require.