title: TypeError: cb is not a function in nodejs?
body: <p>(node:13384) UnhandledPromiseRejectionWarning: TypeError: cb is not a function</p>
  <p>I am using passport js for authentication for my website, I am able to get all routes but when I try to sign up that is post router so in the console I am seeing these err, my data saved in DB but after posting my page loading continuously.
  here these err what I am getting</p>
  <blockquote>
  <p>(node:13384) UnhandledPromiseRejectionWarning: TypeError: cb is not a function
  at C:\Users\SBCS\Desktop\AppBlog\node_modules\passport-local-mongoose\index.js:247:59
  at processTicksAndRejections (internal/process/task_queues.js:93:5)
  (Use <code>node --trace-warnings ...</code> to show where the warning was created)
  (node:13384) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag <code>--unhandled-rejections=strict</code> (see <a href="https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode" rel="nofollow noreferrer">https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode</a>). (rejection id: 1)
  (node:13384) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</p>
  </blockquote>
  <p>and here is my post router code</p>
  <pre><code>  app.post(&quot;/sign-up&quot;,(req,res)=&gt;{
  
      const username = req.body.username
      const email = req.body.email
      const password = req.body.password
  
   User.register( {username:username}, req.body.email,req.body.password ,(err,user)=&gt;{
       if(err){
           console.log(err);
           res.redirect(&quot;/sign-up&quot;)
          }else{
  passport.authenticate(&quot;local&quot; )(req,res, function (){
      res.redirect('/compose')
  })
       }
       
  
   })
  </code></pre>
  <p>and here is my mongoose connection</p>
  <pre><code>    mongoose.connect('mongodb://localhost:27017/blog', {useNewUrlParser: true, useUnifiedTopology: true,useFindAndModify: false}).catch(err =&gt; console.log(err))
  mongoose.set('useCreateIndex',true);
  </code></pre>
  <p>thanks</p>
  <p>when I am getting err node js referring me this modules code see here</p>
  <pre><code>schema.statics.register = function(user, password, cb) {
  // Create an instance of this in case user isn't already an instance
  if (!(user instanceof this)) {
    user = new this(user);
  }
  
  const promise = Promise.resolve()
    .then(() =&gt; {
      if (!user.get(options.usernameField)) {
        throw new errors.MissingUsernameError(options.errorMessages.MissingUsernameError);
      }
    })
    .then(() =&gt; this.findByUsername(user.get(options.usernameField)))
    .then(existingUser =&gt; {
      if (existingUser) {
        throw new errors.UserExistsError(options.errorMessages.UserExistsError);
      }
    })
    .then(() =&gt; user.setPassword(password))
    .then(() =&gt; user.save());
  
  if (!cb) {
    return promise;
  }
  
  promise.then(result =&gt; cb(null, result)).catch(err =&gt; cb(err));
  </code></pre>
  <p>};
  this is passport-local-mongoose module code</p>