0

I'm working on a simple Node.js register/login, and I want the error message to disappear after 2 seconds.

if (password.length < 6) {
  setTimeout(errors.push({ msg: 'Password must be at least 6 characters' }), 2000);
}

However, I get an error:

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 2 at setTimeout (timers.js:122:11)

David
  • 321
  • 10
  • 23
  • You're calling `errors.push` *immediately* and are passing whatever it returns (likely nothing) to `setTimeout` to be called later (which obviously fails). – deceze Apr 16 '20 at 09:04

1 Answers1

0

Refactor your code as below sir:

if (password.length < 6) {
   setTimeout(function() {errors.push({msg: 'Password must be at least 6 characters' })},2000); 
}
Santhosh J
  • 368
  • 3
  • 14
rubberduck
  • 11
  • 1