question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: cb is not a function

See original GitHub issue

I’ve encountered this error. When logging out from the web application it throws a TypeError.

My code that is in use:

var mongoose = require('mongoose')
mongoose.Promise = global.Promise 
var session = require('express-session')
var MongoStore = require('connect-mongo')(session)

app.use(session({
  secret: "verySecretKey",
  resave: true,
  saveUninitialized: true,
  cookie: { maxAge: 19 * 60000 }, // store for 19 minutes
  store: new MongoStore({
	mongooseConnection: mongoose.connection
  })
}))

process.on('unhandledRejection', (reason, p) => {
  console.log('app.js - Unhandled Rejection at: \nPromise', p, '\nreason:', reason);
});

The code which runs when logging out:

router.get(['/login','/logout'], function(req, res){
  req.session.destroy()
  res.redirect("/")
})

Console output after logout:

app.js - Unhandled Rejection at: 
 Promise Promise {
  <rejected> TypeError: cb is not a function
    at promise.then.res (/home/efkan/Projects/awesome/node_modules/connect-mongo/src/index.js:7:18)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7) } 
reason: TypeError: cb is not a function
    at promise.then.res (/home/efkan/Projects/awesome/node_modules/connect-mongo/src/index.js:7:18)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

The error specifies this line of connect-mongo source code

Development environment:

Module Name Version
connect-mongo 2.0.0
mongoose 4.12.4
express-session 1.9.3
express 4.10.6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jdesboeufscommented, Dec 10, 2017

You have to pass a callback in your destroy call. req.session.destroy(cb)

0reactions
jdesboeufscommented, Jan 5, 2018

Fixed in version 2.0.1. Thx @brainthinks!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: cb is not a function - javascript - Stack Overflow
1. You aren't passing any cb s to any of the three functions that require a callback as a second parameter. – CertainPerformance...
Read more >
TypeError: cb is not a function #917 - tediousjs/tedious - GitHub
Hi @Steexyz, for the 'cb' function issue, there is a change under PR #845 that has been recently merged into master which introduce...
Read more >
How I fixed a "cb.apply is not a function" error ... - Flavio Copes
I regularly use Gitbook, a little Node.js software used to generate an ebook from a set of markdown files. I use it for...
Read more >
Android : TypeError: cb.apply is not a function - YouTube
https://www.hows.tech/p/recommended.html ] Android : TypeError : cb.apply is not a function Note: The information provided in this video is as it ...
Read more >
npm ERR! cb.apply is not a function SOLVED - YouTube
How to solve npm ERR! cb.apply is not a function is shown. ... npm ERR! cb.apply is not a function SOLVED | node...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found