title: Getting error in hapi server
body: <p>I am building a simple log app and have tried to implement modularity to make the code more readable. However I am running into some trouble when I start my app. I have two files, <code>index.js</code> which is where I have my server configuration and have <code>routes.js</code> where I have my routing logic.
  The way I have written my routes is in accordance to the api documentation found in <a href="https://github.com/hapijs/hapi/blob/master/docs/Reference.md#route-options" rel="nofollow">the hapi api</a>.</p>
  
  <p>I am hoping someone could help me understand why I am getting the following error:</p>
  
  <pre><code>/Users/mario/projects/loGym/node_modules/hapi/node_modules/hoek/lib/index.js:425
      throw new Error(msgs.join(' ') || 'Unknown error');
            ^
  Error: Missing or undefined handler: /
      at Object.exports.assert (/Users/mario/projects/loGym/node_modules/hapi/node_modules/hoek/lib/index.js:425:11)
      at new module.exports.internals.Route (/Users/mario/projects/loGym/node_modules/hapi/lib/route.js:36:10)
      at /Users/mario/projects/loGym/node_modules/hapi/lib/router.js:110:25
      at Array.forEach (native)
      at /Users/mario/projects/loGym/node_modules/hapi/lib/router.js:107:17
      at Array.forEach (native)
      at internals.Router.add (/Users/mario/projects/loGym/node_modules/hapi/lib/router.js:104:13)
      at internals.Server._route (/Users/mario/projects/loGym/node_modules/hapi/lib/server.js:471:18)
      at internals.Server.route (/Users/mario/projects/loGym/node_modules/hapi/lib/server.js:465:10)
      at Object.&lt;anonymous&gt; (/Users/mario/projects/loGym/index.js:10:8)
  </code></pre>
  
  <p>Am I not exporting the module correctly?</p>
  
  <p>Here is my code for <code>routes.js</code>:</p>
  
  <pre><code>var path = require('path');
  var _ = require('underscore');
  var couchbase = require('couchbase');
  
  //Connect to database.
  
  var db = db || new couchbase.Connection({host: 'localhost:8091', bucket: 'default'}, function(err) {
      if (err) {
        console.log('Connection Error', err);
      } else {
        console.log('Connected!');
    }
   });
  console.log(db);
  
  
  module.exports = [
      {method: 'GET', path: '/static/{param*}', config: { handler: { directory: { path: 'static'}}}},
      {method: 'GET', path:'/', config: landingPage},
      {method: 'GET', path:'/workouts', config: getWorkouts},
      {method: 'GET', path:'/workouts/musclegroup', config: getMusclegroup},
      {method: 'POST', path:'/addworkout', config: addWorkout}
  ];
  
  
  
  var landingPage = {
      handler: function(req, reply) {
          reply.file('index.html');
      }
  };
  
  var getWorkouts = {
      handler: function (req, reply) {
          // set options for databse query
          var q ={
            descending: true,
            stale: false
          };
  
          // show multiple exercises - db.view(designDocument, viewName, options)
          db.view('workout', 'exercise', q).query(function(err, values){
              // use pluck method from underscore to retrieve data
              var keys = _.pluck(values, 'id');
              console.log("Keys: " + keys);
  
              //fetch multiple documents based on the 'keys' object
              db.getMulti(keys, null, function(err, results){
                  console.log('Results: ' + results);
  
                  var workouts = [];
                  for (var prop in results) {
                    workouts.push(results[prop].value);
                  }
                  reply(workouts);
              });
          });
      }
  };
  
  
  var getMusclegroup = {
    handler: function (req, reply) {
          var q = {
            descending: true,
            stale: false
          };
  
          db.view('workout', 'exercise', q).query(function(err, values){
  
              var keys = _.pluck(values, 'id');
  
              db.getMulti(keys, null, function(err, results){
  
                  var muscleGroups = [];
                  for (var prop in results) {
                      console.log(typeof results);
                      console.log(results[prop].value.workout);
                      muscleGroups.push(results[prop].value.workout);
                  }
                  reply(muscleGroups[0]);
              });
          });
      }
  };
  
  
  var addWorkout = {
      handler: function(req, reply){
  
        var d = new Date();
        var cd = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear();
  
        // sets schema for workout
        var payload = {
            "personId": "personId", //to later be replaced with actual username
            "date": cd,
            "workout": [
                {
                  "exercise": req.query.exercise,
                  "musclegoup": req.query.musclegroup,
                  "sets": [
                    {
                      "reps": req.query.reps,
                      "kg": req.query.kg
                    }
                  ]
                }
            ]
        };
  
        // defines unique key for data
        var key = payload.personId + payload.date;
        console.log(key);
  
        // adds payload to database
        db.add(key, payload, function(error, results){
            if (error) {
                console.log(error);
                reply(error + "\n");
            }
            console.log(results);
            reply(payload);
        });
      }
  };
  </code></pre>
  
  <p>And this is my code for <code>index.js</code>:</p>
  
  <pre><code>var Hapi = require('hapi');
  var path = require('path');
  var Joi = require('joi');
  var rs = require('./lib/modules/routes.js');
  
  
  var config= { };
  var server = Hapi.createServer(process.env.PORT || 8080, config);
  
  server.route(rs);
  
  server.start(function(){
    console.log("Server started: " + server.info.uri);
  });
  
  module.exports = server;
  </code></pre>