title: The "listener" argument must be of type function. Received undefined
body: <p>I ran this script to connect to MongoDB using mongoose.</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  mongoose.connect(&quot;mongodb://localhost/curious&quot;, { useNewUrlParser: true });
  const db = mongoose.connection;
  
  const dbLog = (msg) =&gt; {
      console.log(`[DATABASE] [SUCCESS] ${msg}`);
  }
  
  const dbLogError = (msg) =&gt; {
      console.error(`[DATABASE] [ERROR] ${msg}`);
  }
  
  db.on(&quot;error&quot;, dbLogError(&quot;Database connection failure&quot;));
  db.once(&quot;open&quot;, () =&gt; {
      dbLog(&quot;Database connection successful&quot;);
  })
  
  mongoose.connection.close()
  </code></pre>
  <p>I received the following error</p>
  <pre><code>PS D:\scripts&gt; node .\dbUtils.js
  [DATABASE] [ERROR] Database connection failure
  events.js:110
      throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
      ^
  
  TypeError [ERR_INVALID_ARG_TYPE]: The &quot;listener&quot; argument must be of type function. Received undefined
      at checkListener (events.js:110:11)
      at _addListener (events.js:347:3)
      at NativeConnection.addListener (events.js:405:10)
      at Object.&lt;anonymous&gt; (D:\Workspace\curious-backend\scripts\dbUtils.js:13:4)
      at Module._compile (internal/modules/cjs/loader.js:1015:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
      at Module.load (internal/modules/cjs/loader.js:879:32)
      at Function.Module._load (internal/modules/cjs/loader.js:724:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
      at internal/main/run_main_module.js:17:47 {
    code: 'ERR_INVALID_ARG_TYPE'
  }
  </code></pre>
  <p>What is this error and how can I fix this?</p>
  <p>Stackoverflow won't let me post without more text, so, all of you have a great day. These are tough times. Love yourself and take care.</p>