{"id":4653,"date":"2016-07-08T01:46:54","date_gmt":"2016-07-08T01:46:54","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4653"},"modified":"2016-07-08T01:46:54","modified_gmt":"2016-07-08T01:46:54","slug":"fixin-express-js-error-route-get-requires-callback-functions-got-object-undefined","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixin-express-js-error-route-get-requires-callback-functions-got-object-undefined\/","title":{"rendered":"Fixin Express.js error: Route.get() requires callback functions but got a [object Undefined]"},"content":{"rendered":"<p>If you write a new Express View, you may get an error like so:<\/p>\n<pre lang=\"javascript\">\nError: Route.get() requires callback functions but got a [object Undefined]\n    at Route.(anonymous function) [as get] (\/Users\/gary\/hackathon-starter\/node_modules\/express\/lib\/router\/route.js:196:15)\n    at EventEmitter.app.(anonymous function) [as get] (\/Users\/gary\/hackathon-starter\/node_modules\/express\/lib\/application.js:481:19)\n    at Object.<anonymous> (\/Users\/gary\/hackathon-starter\/app.js:111:5)\n    at Module._compile (module.js:541:32)\n    at Object.Module._extensions..js (module.js:550:10)\n    at Module.load (module.js:456:32)\n    at tryModuleLoad (module.js:415:12)\n    at Function.Module._load (module.js:407:3)\n    at Function.Module.runMain (module.js:575:10)\n    at startup (node.js:159:18)\n    at node.js:444:3\n<\/pre>\n<p>This is an indication that the controller is declaring some export (or maybe not) , and that when you reference it, it is undefined (similar variations include you exporting an object instead of a function).<\/p>\n<p>When you reference the controller you may be doing something like so:<\/p>\n<pre lang=\"javascript\">\napp.get('\/schedule', calendarController.getSchedule);\n<\/pre>\n<p>So in order for this to work the controller would need to have a matching function exported:<\/p>\n<pre lang=\"javascript\">\nexports.getSchedule = (req, res) => {\n  res.render('schedule', {\n    title: 'Schedule A Meeting'\n  });\n};\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Fixing a vague error from Node when adding new views<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[209,302,388,389],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4653"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4653"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4653\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}