3gwebtrain
3gwebtrain

Reputation: 15293

express - app `index.jade` not properly supplied by the `exports` function

I am trying to make a app, in the app directory this is my app.js file. in the app.js I am requiring the router folder and exporting the Routes. But I am not able to render the index.jade using the Router instead i am getting error:

D:\Projects\socialApp\node_modules\express\lib\router\index.js:423
      throw new TypeError(msg);
            ^
TypeError: Router.use() requires callback function but got a [object Undefined]
    at D:\Projects\socialApp\node_modules\express\lib\router\index.js:423:13
    at Array.forEach (native)
    at Function.use (D:\Projects\socialApp\node_modules\express\lib\router\index
.js:419:13)
    at D:\Projects\socialApp\node_modules\express\lib\application.js:178:21
    at Array.forEach (native)
    at Function.use (D:\Projects\socialApp\node_modules\express\lib\application.
js:175:7)
    at Object.<anonymous> (D:\Projects\socialApp\app.js:22:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

D:\Projects\socialApp>

here is my app.js:

var express    = require("express"),
passport       = require("passport"),
passportLocal  = require("passport-local"),
bodyParser     = require("body-parser"),
cookieParser   = require("cookie-parser"),
expressSession = require("express-session"),
jade           = require("jade"),
mongoose       = require("mongoose"),
routes         = require('./routes'),
port           = process.env.PORT || 3000,

    app = express();

    app.set('view engine', 'jade');
    app.set('views', __dirname + '/views');
    app.use(express.static(__dirname + '/public'));


    app.use(passport.initialize());

    var routes = require('./routes/index')(passport); //i am calling here
    app.use('/', routes); // not getting index.jade on screen.


app.listen(port, function(){
    console.log('Port Listing to ' + port + ":" + __dirname);
});

here is what in the router folder and in the index.js:

var express = require('express'),
router      = express.Router();

module.exports = function(passport){

    router.get('/', function(req,res){
        res.render('index'); //i am not getting index.jade from view folder getting error
        });
}

any one figure-out the issue please?

Upvotes: 0

Views: 120

Answers (1)

mscdex
mscdex

Reputation: 106696

You need to return router; at the end of your module.exports function.

Upvotes: 2

Related Questions