Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

445
Views
throw new TypeError("expecting a function but got " + util.classString(fn)); TypeError: expecting a function but got [object Undefined]

While running node app.js the Express server is connecting properly and the MongoDB is connecting correctly, but I am facing a problem in the node module as mentioned above.

The complete log is pasted below:

        throw new TypeError("expecting a function but got " + util.classString(fn));
        ^

TypeError: expecting a function but got [object Undefined]
    at Function.Promise.promisify (D:\Project\DD-NODEJS\node_modules\bluebird\js\release\promisify.js:270:15)
    at D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:155:56
    at Array.forEach (<anonymous>)
    at MongoStore.setCollection (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:154:67)    
    at MongoStore.handleNewConnectionAsync (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:120:18)
    at NativeConnection.<anonymous> (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:91:72) 
    at Object.onceWrapper (node:events:509:28)
    at NativeConnection.emit (node:events:402:35)
    at NativeConnection.Connection.onOpen (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:647:8)
    at _setClient (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:895:8)
    at D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:797:7
    at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\utils.js:423:9
    at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\mongo_client.js:130:17 at connectCallback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:29:9)
    at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:80:9    
    at Object.callback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\sdam\topology.js:230:17)

To view Index.js Click Here To view App.js Click Here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hi was facing a similar issue while connecting MongoDB session in nodejs.

Steps to fix:

  1. update the mongoose and connect-mongo package.

  2. update the require statement. Remove (session) from it. const MongoStore = require('connect-mongo');

  3. update the code

    app.use(
     session({
     secret: 'story book',
     resave: false,
     saveUninitialized: false,
     store: MongoStore.create({
         mongoUrl: YourDatabaseURL
      })
     })
    );
    
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!