Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Route.get() requires callback functions but got a [object Undefined]

Tags:

node.js

I have problem including controller file in nodejs router file

my router file has

var express = require('express');
var app = new express.Router();
var ctrl = require('../controller/designer.js');
var renderpages = require('../controller/renderingpages.js')
app.use(express.static('public'));

In designer.js file i have a following structure

var ctrl = 
{

  //controller code
}
module.exports = ctrl

in renderingpages.js file i have a following structure

var renderpages = 
{
  //controller code
}
module.exports = renderpages

i have this issue after including renderingpages.js

like image 569
Elamparithi.P Avatar asked Mar 22 '26 12:03

Elamparithi.P


1 Answers

Error: Route.get() refers to some line of code that is a get request.

The error means that when your making your get request you are passing an object rather then the expected callback function needed by the request.

What it should look like:

//Format should be '/route', callback
app.get('/iamroute', function(req, res) {
   //callback
});
like image 126
matt Avatar answered Mar 24 '26 02:03

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!