Node.js: object is not a function


I have just started working with Nodejs and trying to create my first node (using express)application. I am getting an error "TypeError: object is not a function" with below message:

/home/sears/workspace/Express/server.js:38 require('./app/routes.js')(app,passport); ^ TypeError: object is not a function at Object.<anonymous> (/home/sears/workspace/Express/server.js:38:27) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:929:3

My server.js is as follows:

var express = require('express'); var app = express(); var port = process.env.PORT || 8080; var mongoose = require('mongoose'); var passport = require('passport'); var flash = require('connect-flash'); var morgan = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var session = require('express-session'); var configDB = require('./app/config/database.js'); var mysqlDB = require('mysql'); // Config mongoose.connect(configDB.url); // require('./config/passport')(passport); // pass passport for configuration app.use(morgan('dev')); app.use(cookieParser()); app.use(bodyParser()); app.set('view engine', 'ejs'); app.use(session({ secret : 'ilovescotchscotchyscotchscotch' })); app.use(passport.initialize()); app.use(passport.session()); app.use(flash()); // routes require('./app/routes.js')(app, passport); // launch app.listen(port); console.log("The magic is happening on port " + port);

I have explored other questions on SO with similar error messages and tried out things but without help. What I am doing wrong here?


There was an issue with my routes.js which was not completed properly. After doing that I am able to resolve the issue.


  • Node Error: Cannot find module './lib/querystring'
  • Import vue package in laravel
  • Firestore is not a function in Vue CLI application
  • Node.js, Express.js - unexpected token {
  • unexpected indentation error with favicon_tag after migration to rails 5.0
  • Exception in setInterval callback
  • How to use a recursive function to update a table?
  • webpack-dev-server Cannot find module 'webpack'
  • How to use Facebook Graph API after authenticating with Passport.js facebook strategy?
  • Session IDs don't persist unless passport.js is initialized
  • Hyperledger Composer Error Identity has not been registered once issued
  • Nodejs npm scripts fail with “SyntaxError: Unexpected token {”
  • angularjs app web.js structure to deploy on heroku
  • configure babel with WebStorm to use ES6 with WebStorm Node.js project
  • Angular AOT failing at compilation (something with angular/compiler-cli)
  • Openshift node app failed to start
  • Symfony2 plaintext users don't work
  • Removing event listeners on automatically created multiple elements
  • Get a trait object reference from a vector
  • select function not working in 3.5.4 version of d3.js
  • Autofac with Web API 2 - Parameter-less constructor error
  • pillow imaging ImportError
  • Authentication in Play! and RestEasy
  • Django simple Captcha “No module named fields” error
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Meteor helpers not available in Angular template
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • using HTMLImports.whenReady not working in chrome
  • How do I configure my settings file to work with unit tests?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is it possible to post an object from jquery to bottle.py?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal